API purpose: Finding local air quality from address
Signup: air quality has no signup google, as always, does.
Documentation: https://developers.google.com/maps/web-services/client-library
Github: https://github.com/gregario/API-Month/tree/master/Day7%20AQ%20Project
Comment: Wrapping up the first week into a useful script
So today was a culmination of all the learnings I achieved this week…. A bit of background on this one. I decided to do something a bit more abitious today. Since I now have the basic building blocks of data for getting and manipulating JSON API data I thought I would put it to the test for something more than one localised test. So today I’m going to build something chunkier. Using the work I’ve done all week from data manipulation, geocaching and the air quality API, I want to build an app that if you put in a post code in London it finds the nearest AQ monitor from the list and returns its air quality data.
This is more challenging than it sounds, the basic work flow would be.
Take input address and convert to GPS. Pull down list of all London Air Quality monitors and extract their locations. Do a diff between the two to find the closest distance from that new list. Then from that new list pull down a list of sensors associated with that sensor. Then from this pull down their data and average it for the day.
What I can then use this to do is to give Air quality information as an extension to map or location searches. An interesting wrapper library for future work. I’m going to try some more complex error handling in this too, as I’ve been pretty lax with this up until now.
As I’ve moved onto commenting inline the code should be self explanatory, it produces some nice pretty outputs too!
|
|
On the code, apologies but the white spaces were not preserved when I copied it over, have a look at the github to get a more human readable version of the code.
Running
Gives
|
|
Turns out the air quality around work is pretty good, for NO2 43ug/m3 average is right at the 40ug/m3 target for a yearly average. Yay 🙂
One thing I’ve noticed from this work is I need to have a play with times and dates to do it neatly. Tomorrow I’m going to play with NTP servers and the date module in python. Its a slight divergence from the API calling but will be a useful function to plug into other functions in the future.