Using Python to Fetch API Data into CSV

Поделиться
HTML-код
  • Опубликовано: 17 окт 2024
  • Today, ill be demonstrating a nice beginner 'project' to show how you can quickly and easily build a python script using standard modules to fetch data from an API and write it to a CSV. In this video we'll be using a public API provided from Coincap to grab cryptocurrency prices and write them into a CSV file. I encourage anyone who watches this to expand this out to present this in a webpage or maybe even upload the CSV to Google Sheets!
    A great resource for getting free publicly available API's as seen in this video is from this repo here : github.com/pub...
    📧 Weekly mail dedicated to solo devs looking to make it online: danielotto.bee...
    ☕Buy me a coffee: buymeacoffee.c...
    If you found this video helpful and would like to support my channel make sure you give the sub button a smash so you also dont miss out on video's like this in the future! :)
    Note: In this video I am using Python v3.9.4

Комментарии • 44

  • @renan6827
    @renan6827 6 месяцев назад +1

    Great tutorial!!! Short, precise and very straightforward😁. No time wasting. Your video helped a lot. Much appreciate !!!!

  • @PoolNinjasTN
    @PoolNinjasTN 2 года назад +2

    Hey boss, so im having the issue
    typeError: list indices must be integers or slices, not str
    for the for x in function
    My "in" is purple
    yours is blue.
    Ideas? Im new to python!

  • @griffingillam9800
    @griffingillam9800 Год назад

    thank you so much for the walkthrough. been trying to find a way to do this for a few days now and your video worked perfectly

  • @doop9134
    @doop9134 Год назад

    I love your tutorial! Short & precise & super helpful! This helped a lot! Thanks so much!! 💙

  • @memo.a937
    @memo.a937 5 месяцев назад

    I want to do the same thing but the problem i have is that the json response have so many levels, any Idea how to reach these data in the inner levels

  • @thean1585
    @thean1585 2 года назад +1

    thankyou for the tutorial, im just starting to learn python but im sure this will be useful in the future!

  • @monikak6212
    @monikak6212 Год назад +1

    I use ur code for different api,but i use to get error list indices must be integer or slices,not str

  • @financephofun7090
    @financephofun7090 2 года назад +1

    Thank you Daniel! I used your code to practice on different different API to csv file, it was very helpful, not sure if you have any plans, it would be nice if we took the csv file and did some analysis

  • @MegaGroover
    @MegaGroover 2 года назад +1

    Thank you very much, really good tutorial! I'm so happy it worked!

  • @youtubewatch3981
    @youtubewatch3981 2 года назад

    thanks for your video Daniel, i try to use same way to pull options data and format like your style.. but i can't find the "data" and i try to run it. the error :for x in myjson['strikePrice']:
    TypeError: string indices must be integers
    [Finished in 2.524s]

  • @easylearnfrench
    @easylearnfrench Год назад

    Hi, thank you for your helpful video.
    how can I access to second entry?
    e.g there is an order_id with two different rows like below
    row #1 order id: i6tp-pucp-dsrx-1gg7-ikef item_no: 2304
    row #2 order id: i6tp-pucp-dsrx-1gg7-ikef item_no: 10914

  • @zuriatnaveed6723
    @zuriatnaveed6723 2 года назад

    myjson = response.json()
    TypeError: 'NoneType' object is not callable
    how to solvs this error??

  • @-majidkids8087
    @-majidkids8087 2 года назад +1

    for x in myjson['data']:
    KeyError: 'data'
    how i can resolve this problem please ?
    i write same your code

    • @danielotto
      @danielotto  2 года назад +1

      Hey Majid, are you using the same API as in the video? Because the API returns a response of an object like { *data* : [{ id: bitcoin, rank : 1 }] etc we are referencing the key in that response object which is the word *data* . If your using another API the response could be different and the key is likely different aswell. If your using a different API you need to reference the key value name in myjson['data']

    • @-majidkids8087
      @-majidkids8087 2 года назад

      @@danielotto the key value is : {"txs":

    • @danielotto
      @danielotto  2 года назад +1

      if it is something like that then you would need to do : mydata['txs']
      However if it is nested and your data looks like this from the api : { "data" : [{ "txs" : 3 } ,{"txs" : 5 ]} then you would need to do something like myjson['data']['txs']
      It's hard to know without seeing what kind of response your API is giving you but hope that helps :)

    • @-majidkids8087
      @-majidkids8087 2 года назад

      @@danielotto can i send my code to see it please ?

    • @-majidkids8087
      @-majidkids8087 2 года назад

      @@danielotto thank you very much sir

  • @JasonSvoboda
    @JasonSvoboda 2 года назад

    How do you approach this if they do not have a top level organizer like data and instead are just the individual items strings themselves?

    • @danielotto
      @danielotto  2 года назад +1

      The name ‘data’ is simply the key to the value which is the array. If you have just individual items you should able to select on those individual key names to read their respective values. You can google ‘How to get values by key in python’ and their should be a few examples :)

  • @historique1
    @historique1 2 года назад

    Exactly what I needed, thank you so much!!

  • @VanioJR
    @VanioJR 2 года назад

    your tutorial is very good, it helped me a lot! thank you so much!

  • @thippeswamykv242
    @thippeswamykv242 2 года назад

    What is the method for storing post api into csv

  • @pleabargain
    @pleabargain 2 года назад +1

    Very helpful! Thank you!

  • @whatarewetoday4585
    @whatarewetoday4585 2 года назад

    ...Broooo, I will make you dinner, anything you want. You want to order in courses I got you. This was so helpful

    • @danielotto
      @danielotto  2 года назад

      Haha thanks mate glad you found it useful!

  • @qb9496
    @qb9496 2 года назад +1

    Can you do a tutorial on google places api to csv? Name, address, phone

  • @nftichie
    @nftichie Год назад

    Love this video

  • @ashu__risiofficial5887
    @ashu__risiofficial5887 2 года назад

    Saved my job bro ☺️☺️☺️

  • @2010aishwary
    @2010aishwary 2 года назад

    how do we filter if the data has more nested arrays ?

    • @danielotto
      @danielotto  2 года назад

      If they are nested arrays you would do : myjson[‘data’][0] , replacing 0 with the required index. If it is nested objects then myjson[‘data’][‘nestedobject’]. Hope this helps!

    • @2010aishwary
      @2010aishwary 2 года назад

      @@danielotto got it. I am a bit new to this had to loop through multiple lists and dictionaries. Thanks for this amazing video helped a lot.

  • @v.abhinav5637
    @v.abhinav5637 Год назад

    the prices are so different today . i just forget the price back then

  • @natalyescamilla7022
    @natalyescamilla7022 2 года назад

    Daniel, working on a piece for API to csv and would love to get some 1-1 with you. Have two days to complete it. Let me know, Thank you

    • @danielotto
      @danielotto  2 года назад

      Hey Nataly, what are you needing help with on that?

    • @natalyescamilla8907
      @natalyescamilla8907 2 года назад

      @@danielotto need to call multiple GET API calls to find temperature, humidity, vehicle, close to real time.

    • @natalyescamilla7022
      @natalyescamilla7022 2 года назад

      @@danielotto Hey, Do you happen to have any content on updating the csv every 30 mins? I'm trying to use the schedule module but not getting anything

    • @danielotto
      @danielotto  2 года назад +1

      @@natalyescamilla7022 Depending where you're running it from, you could setup a server with a cron job if on linux or a windows service to trigger the script. You could even use something like Zapier which could do most of the scheduling for you but you would need to be able to send the file back to yourself through some other email or storage API. Hope this helps :)

  • @navdeepkaur4574
    @navdeepkaur4574 2 года назад

    Thnks alot 😊

  • @Reeg3x
    @Reeg3x 2 года назад

    Bump