Skip to content

Instantly share code, notes, and snippets.

@pceccato
Created September 15, 2012 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pceccato/3728308 to your computer and use it in GitHub Desktop.
Save pceccato/3728308 to your computer and use it in GitHub Desktop.
Calling wunderground weather api...
import urllib2
import json
# make sure you put your api key in the request string
def getWeatherFromWunderground(country, city):
request = 'http://api.wunderground.com/api/YOUR_API_KEY_HERE/geolookup/conditions/forecast/q/%s/%s.json' % (country, city)
f = urllib2.urlopen(request)
json_string = f.read()
f.close()
parsed_json = json.loads(json_string)
location = parsed_json['location']['city']
# temp_c = parsed_json['current_observation']['temp_c']
# weather = parsed_json['current_observation']['weather']
# print "%s. Current temperature in %s is: %s degrees celcius" % (weather, location, temp_c )
return parsed_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment