Wunderground API: One City: Today's Forecast - edorlando07/datasciencecoursera GitHub Wiki

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

It pulls one city's current daily forecast.

import urllib2
import json  

Below is the url used in the API. The cb8d75######## represents the unique key that was given when I signed up.

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

parsed_json = json.loads(json_string)

location = parsed_json['location']['city']
temp_f = parsed_json['current_observation']['temp_f']
feelslike_f = parsed_json['current_observation']['feelslike_f']
weather = parsed_json['current_observation']['weather']
wind_mph = parsed_json['current_observation']['wind_mph']
precip_today_in = parsed_json['current_observation']['precip_today_in']


print "Location: " + str(location)
print "Temperature: " + str(temp_f)
print "Feels like: " + str(feelslike_f)
print "Weather: " + str(weather)
print "Wind MPH: " + str(wind_mph)
print "Precipitation in Inches: " + str(precip_today_in)

f.close()