Wunderground API: One City: 10 Day Forecast - edorlando07/datasciencecoursera GitHub Wiki

###The code below is basic weather data from the wunderground API.

It pulls one city's current 10 day forecast.

import urllib2
import json  

day_range = range(2)  #sets up number of days to pull from 10 day forecast.

The url below includes an API key that is unique (cb8d75#########).

f = urllib2.urlopen('http://api.wunderground.com/api/cb8d75#########/forecast10day/q/IL/Chicago.json')
json_string = f.read()

parsed_json = json.loads(json_string)

for day_n in day_range:
    title = parsed_json['forecast']['txt_forecast']['forecastday'][day_n]['title']
    fcttext = parsed_json['forecast']['txt_forecast']['forecastday'][day_n]['fcttext']

    print str(title) + "'s forecast is: " + str(fcttext)
    print

f.close()