[CentralOH] Code from last night's Beginner's Python talk

Eric Floehr eric at intellovations.com
Tue Sep 29 20:50:52 CEST 2015


import urllib2

# The API url to call
key = 'f6a..........15a'
url = '
http://api.wunderground.com/api/{key}/geolookup/conditions/q/France/Paris.json'.format(key=key)

# Open the page and store as a string
page = urllib2.urlopen(url)
json_string = page.read()
page.close()

# Read the string and parse as JSON data
data = json.loads(json_string)

# Pull out information from the JSON data
location = data['location']['city']
obs = data['current_observation']
temp_f = obs['temp_f']
condition = obs['weather']

print("In {loc} it is {temp:.0f} and {cond}".format(loc=location,
temp=temp_f, cond=condition))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20150929/d2a93a5c/attachment.html>


More information about the CentralOH mailing list