Created
November 27, 2012 02:32
-
-
Save brwnj/4152026 to your computer and use it in GitHub Desktop.
grab the current temp and the forecast for the next few days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# encoding: utf-8 | |
import json | |
import urllib2 | |
# weather underground api key | |
api_key = '' | |
u = urllib2.urlopen("http://api.wunderground.com/api/%s/geolookup/q/autoip.json" % api_key) | |
loc = json.load(u) | |
u.close() | |
u = urllib2.urlopen("http://api.wunderground.com/api/%s/conditions/forecast/q/%s.json" % \ | |
(api_key, loc[u'location'][u'zip'])) | |
wug = json.load(u) | |
u.close() | |
print "Weather for %s:\n----------------------------" % \ | |
wug[u'current_observation'][u'display_location'][u'full'] | |
print "Current temperature: %sF\n" % wug[u'current_observation'][u'temp_f'] | |
for day in wug[u'forecast'][u'txt_forecast'][u'forecastday']: | |
print "%s: %s\n" % (day[u'title'],day[u'fcttext']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment