-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget-weather-data.py
35 lines (22 loc) · 1.11 KB
/
get-weather-data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from weatherdata_utils import WeatherStation
import datetime as dt
from time import sleep
from pytz import reference
from email.utils import parsedate_to_datetime
station_urls = ["http://w1.weather.gov/xml/current_obs/KNYC.xml",#Central Park
"http://w1.weather.gov/xml/current_obs/KLGA.xml",#La Guardia Airport
"http://w1.weather.gov/xml/current_obs/KJRB.xml",#Downtown Manhattan
"http://w1.weather.gov/xml/current_obs/KJFK.xml"]#JFK Airport
stations = [WeatherStation(station_url) for station_url in station_urls]
#poll station every 15 minutes
while True:
#or write to file instead
with open('weatherdata','a') as wd:
for st in stations:
#check for the most recent measssurement
if st.update():
print('station',st.ID(),'was updated')
wd.write('{0},{1},{2},{3},{4},{5}\n'.format(st.time(),st.ID(),st.temp(),
st.humidity(),st.pressure(),st.wind_speed()))
print('going to sleep ..')
sleep(15*60)