Skip to content

Instantly share code, notes, and snippets.

@m1el
Created October 15, 2018 22:07
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 m1el/5ee9cd03321aaa4dfb15b079eba7883c to your computer and use it in GitHub Desktop.
Save m1el/5ee9cd03321aaa4dfb15b079eba7883c to your computer and use it in GitHub Desktop.
downloading weather data because Mr. Grey is too lazy
import requests
url = 'https://api-ak.wunderground.com/api/d8585d80376a429e/history_{:04}{:02}{:02}{:04}{:02}{:02}/lang:EN/units:english/bestfct:1/v:2.0/q/EGLL.json?showObs=0&ttl=120'
for year in range(1996, 2018+1):
print(url.format(year, 8, 1, year, 8, 31))
text = requests.get(url.format(year, 8, 1, year, 8, 31)).text
with open('{}-08.json'.format(year), 'w+') as fd:
fd.write(text)
import json
avg_temps = []
max_temps = []
for year in range(1996, 2018+1):
with open('{:04}-{:02}.json'.format(year, 8)) as fd:
data = json.load(fd)
avg_temps.append(data['history']['summary']['temperature_avg'])
max_temps.append(data['history']['summary']['max_temperature_max'])
print('avgs={};'.format(avg_temps))
print('maxs={};'.format(max_temps))
xs=[1996:1:2018];
% below is output of 02_extract.py
avgs=[65, 70, 64, 64, 66, 65, 66, 69, 66, 64, 63, 62, 64, 65, 62, 63, 66, 66, 63, 64, 67, 63, 66];
maxs=[89, 87, 86, 91, 77, 87, 86, 98, 86, 87, 82, 82, 80, 82, 77, 84, 86, 93, 79, 87, 91, 81, 90];
plot(xs,avgs,";avg temp;","color","blue",xs,maxs,";max temp;","color","red");
grid on
grid minor on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment