Skip to content

Instantly share code, notes, and snippets.

@philshem
Last active November 15, 2018 09:17
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save philshem/8864437 to your computer and use it in GitHub Desktop.
Wunderground API: Streamlined python 2.7 code using the requests package. Must register at http://www.wunderground.com/weather/api/ and insert your personal key.
import requests
data = requests.get('http://api.wunderground.com/api/INSERT_KEY_HERE/geolookup/conditions/q/Switzerland/Zurich.json').json()
location = data['location']['city']
temp_c = data['current_observation']['temp_c']
print "Current temperature in %s is: %s C" % (location, temp_c)
import requests
def get_precip(gooddate):
urlstart = 'http://api.wunderground.com/api/INSERT_KEY_HERE/history_'
urlend = '/q/Switzerland/Zurich.json'
url = urlstart + str(gooddate) + urlend
data = requests.get(url).json()
for summary in data['history']['dailysummary']:
print ','.join((gooddate,summary['date']['year'],summary['date']['mon'],summary['date']['mday'],summary['precipm'], summary['maxtempm'], summary['meantempm'],summary['mintempm']))
if __name__ == "__main__":
from datetime import date
from dateutil.rrule import rrule, DAILY
a = date(2013, 1, 1)
b = date(2013, 12, 31)
for dt in rrule(DAILY, dtstart=a, until=b):
get_precip(dt.strftime("%Y%m%d"))
@KiranPrajapati345
Copy link

It's very useful,I have using your code to get data, can you tell me if I want to data for month wise, not day wise ,then what I have to changes in your code?
for example: I want data for month wise,
year , month, average_high_temp , average_low_temp, precipitation , humadity...
2015 Jan 25 20 0 10 likewise....
can you please help for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment