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

Peter Carswell pcarswell.1 at gmail.com
Thu Oct 1 22:24:09 CEST 2015


Eric,

I have forgotten from your discussion, does the free wunderground
membership provide the json/xml service?

pete

On Tue, Sep 29, 2015 at 2:50 PM, Eric Floehr <eric at intellovations.com>
wrote:

> 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))
>
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20151001/b865c696/attachment.html>


More information about the CentralOH mailing list