Skip to content

Instantly share code, notes, and snippets.

@mfriedenberg
Created December 4, 2014 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mfriedenberg/12d620d67f16ff935bee to your computer and use it in GitHub Desktop.
Save mfriedenberg/12d620d67f16ff935bee to your computer and use it in GitHub Desktop.
import urllib2
import json
key = "[your API key]"
while 1:
zip = raw_input('For which ZIP code would you like to see the weather forecast? ')
url = 'http://api.wunderground.com/api/' + key + '/geolookup/forecast10day/q/' + zip + '.json'
f = urllib2.urlopen(url)
json_string = f.read()
parsed_json = json.loads(json_string)
for day in parsed_json['forecast']['simpleforecast']['forecastday']:
print day['date']['weekday'] + ' (' + day['date']['pretty'] + '):'
print ' Conditions: ' + day['conditions']
print ' High:' + day['high']['fahrenheit'] + 'F'
print ' Low: ' + day['low']['fahrenheit'] + 'F'
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment