Skip to content

Instantly share code, notes, and snippets.

@brwnj
Created November 27, 2012 02:32
Show Gist options
  • Save brwnj/4152026 to your computer and use it in GitHub Desktop.
Save brwnj/4152026 to your computer and use it in GitHub Desktop.
grab the current temp and the forecast for the next few days
#! /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