-
-
Save radumas/a453d61ad219ba3b9ea5bf0d56e7caf5 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.
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
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) |
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
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")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment