Skip to content

Instantly share code, notes, and snippets.

@boxfrommars
Created June 15, 2016 13:57
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 boxfrommars/41fd27548fd6677d71b20e7aa438e745 to your computer and use it in GitHub Desktop.
Save boxfrommars/41fd27548fd6677d71b20e7aa438e745 to your computer and use it in GitHub Desktop.
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