Jump to content

Python API Data read and data sort example


G+_L I
 Share

Recommended Posts

Python API Data read and data sort example. Pulls data from 2 APIs and displays information, allows users to sort the information and make other API calls.

 

I had a tough time with the sorting since the data returned from the API came into a dictionary object and those don't sort like the lists do. I found a workaround online to convert it to a list of tuples (like a list of lists) and then sort that.

 

Lots of good and free APIs on this page:

http://www.webresourcesdepot.com/15-free-apis-you-didnt-hear-about-but-will-make-use-of/

 

and plenty more with a simple Google search.

http://pastebin.com/5QirQybe

Link to comment
Share on other sites

  • 1 year later...

Love the code, learning a lot from it.

 

Open weather now requires an API key. If someone (late to the game as myself) wants to run the code, you may want to change their URL assembly line to something as below:

 

weatherUrl = 'http://api.openweathermap.org/data/2.5/weather?q='+ cityRegion.replace(' ','%20') + '&appid=' + MYAPI_KEY

 

Where MYAPI_KEY was previously stored, of course, with your API key.

 

After you do that, the call line can now have just the variable defined above:

response = urllib2.urlopen(weatherUrl)

 

Hope this helps someone who is wondering what happened.

Link to comment
Share on other sites

 Share

×
×
  • Create New...