Using Python to Fetch API Data into CSV
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/public-apis/public...
📧 Weekly mail dedicated to solo devs looking to make it online: danielotto.beehiiv.com/
☕Buy me a coffee: buymeacoffee.com/danielotto
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
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
I love your tutorial! Short & precise & super helpful! This helped a lot! Thanks so much!! 💙
Great tutorial!!! Short, precise and very straightforward😁. No time wasting. Your video helped a lot. Much appreciate !!!!
Thank you very much, really good tutorial! I'm so happy it worked!
Exactly what I needed, thank you so much!!
your tutorial is very good, it helped me a lot! thank you so much!
thankyou for the tutorial, im just starting to learn python but im sure this will be useful in the future!
Very helpful! Thank you!
Love this video
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
Saved my job bro ☺️☺️☺️
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!
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]
What is the method for storing post api into csv
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
Thnks alot 😊
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
I use ur code for different api,but i use to get error list indices must be integer or slices,not str
myjson = response.json() TypeError: 'NoneType' object is not callable how to solvs this error??
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
Жыл бұрын
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 :)
Can you do a tutorial on google places api to csv? Name, address, phone
how do we filter if the data has more nested arrays ?
@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
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.
...Broooo, I will make you dinner, anything you want. You want to order in courses I got you. This was so helpful
@danielotto
2 жыл бұрын
Haha thanks mate glad you found it useful!
for x in myjson['data']: KeyError: 'data' how i can resolve this problem please ? i write same your code
@danielotto
2 жыл бұрын
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
2 жыл бұрын
@@danielotto the key value is : {"txs":
@danielotto
2 жыл бұрын
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
2 жыл бұрын
@@danielotto can i send my code to see it please ?
@-majidkids8087
2 жыл бұрын
@@danielotto thank you very much sir
the prices are so different today . i just forget the price back then
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
2 жыл бұрын
Hey Nataly, what are you needing help with on that?
@natalyescamilla8907
2 жыл бұрын
@@danielotto need to call multiple GET API calls to find temperature, humidity, vehicle, close to real time.
@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
2 жыл бұрын
@@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 :)
Bump