Retrieving weather data
Next, we will retrieve our final data element: the weather. As mentioned earlier, we will use the WeatherUnderground service that allows us to gather historical weather reports for any place in the world. The weather API is REST-based and JSON-based, so we'll use the urllib
module to request the data and the JSON library to parse it. Note that in this section, we cache the data locally so that you can run the script offline to test, if need be. Early on in this section is where you place your WeatherUnderground API key that is flagged by the text, YOUR KEY HERE
:
log.info("Creating weather summary") # Get the bounding box centroid for georeferencing weather data centx = minx + ((maxx-minx)/2) centy = miny + ((maxy-miny)/2) # WeatherUnderground API key # You must register for free at wunderground.com # to get a key to insert here. api_key = "YOUR API KEY GOES HERE" # Get the location id of the route using the bounding box # centroid and the...