I am trying to pull historical data from the Weather Underground API. I adapted their Python example code (see below). When I run this I get an exception "TypeError: list indices must be integers, not str" The JSON stream includes a bunch of fields with daily summary information (Dailysummary), but I cannot get out and any of the values they have in this list.
I put the URL into a JSON viewer to look at the structure, and cannot figure out what I am doing wrong. Any help would be greatly appreciated.
import urllib2
import json
f = urllib2.urlopen('http://api.wunderground.com/api/d08c4738fb303c66/geolookup/conditions/q/CA/San_Francisco.json')
json_string = f.read()
parsed_json = json.loads(json_string)
location = parsed_json['location']['city']
temp_f = parsed_json['current_observation']['temp_f']
print "Current temperature in %s is: %s" % (location, temp_f)
f.close()
h = urllib2.urlopen('http://api.wunderground.com/api/d08c4738fb303c66/history_19760508/q/CA/San_Francisco.json')
json_string = h.read()
parsed_json = json.loads(json_string)
date = parsed_json['history']['utcdate']['pretty']
print date
print type(parsed_json['history'])
snow = parsed_json['history']['dailysummary']['0']
print snow
h.close()