Created
June 15, 2016 13:57
-
-
Save boxfrommars/41fd27548fd6677d71b20e7aa438e745 to your computer and use it in GitHub Desktop.
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 numpy as np | |
import pandas as pd | |
import time | |
base_url = 'https://www.wunderground.com/history/airport/KBOS/{}/{}/{}/DailyHistory.html?&reqdb.zip=&reqdb.magic=&reqdb.wmo=&format=1' | |
d_range = pd.to_datetime(np.arange('2015-12-29', '2016-06-15', dtype='datetime64[D]')) | |
print(d_range) | |
result = pd.DataFrame() | |
for date in d_range: | |
url = base_url.format(date.year, date.month, date.day) | |
d_csv = pd.read_csv(url, header=0, dtype='str') | |
result = result.append(d_csv, ignore_index=True) | |
print(base_url.format(date.year, date.month, date.day)) | |
print(d_csv.shape[0]) | |
time.sleep(2) | |
fname = 'data/weather_' + str(d_range.min().strftime('%Y-%m-%d')) + '_' + str(d_range.max().strftime('%Y-%m-%d')) + '.csv' | |
result.to_csv(fname, index=False) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment