Last active
December 19, 2016 14:45
-
-
Save boxfrommars/865ed554bcefaeb48c52f55dc2d17392 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 forecastio | |
| import pandas as pd | |
| import time, datetime | |
| from shapely import wkt | |
| import os | |
| api_key = 'Your key' | |
| curr_dir = os.path.dirname(__file__) | |
| groups = pd.read_csv('%s/data/hexagon-groups.csv' % curr_dir, index_col=0) | |
| groups['coords'] = groups['centroid'].apply(lambda pnt: {'lon': wkt.loads(pnt).x, 'lat': wkt.loads(pnt).y}) | |
| for key, group in groups.iterrows(): | |
| now = datetime.datetime.now() | |
| print('polygon', key, group['coords']['lat'], group['coords']['lon']) | |
| path = '%s/data/forecast/%s/p-%s' % (curr_dir, now.date().isoformat(), key) | |
| if not os.path.exists(path): | |
| os.makedirs(path) | |
| forecast = forecastio.load_forecast(api_key, group['coords']['lat'], group['coords']['lon']) | |
| f = open('%s/%s-forecast.csv' % (path, int(time.time())), 'w') | |
| f.write(now.isoformat() + '\n') | |
| f.write(str(key) + '\n') | |
| f.write(forecast.response.text) | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment