In [7]:
from weatherdata_utils import WeatherStation
import datetime as dt
from time import sleep
from pytz import reference
from email.utils import parsedate_to_datetime
In [8]:
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
In [9]:
stations = [WeatherStation(station_url) for station_url in station_urls]
In [ ]:
In [10]:
#update all the sations
for station in stations:
station.update()
In [11]:
#show all the values temp,humidity,pressure for all the stations
for st in stations:
print(st.time(),st.ID(),st.temp(),st.humidity(),st.pressure())
In [ ]:
#to combine all the parameters the simplest option could be to
#average them but a weighted average based on distance may yield
#more accurate results
In [6]:
#check for new data every 15 minutes
while True:
for st in stations:
st.update()
#check weather the sation's data was updated within the past 15 minutes
if (dt.datetime.now(dt.timezone.utc) - st.time()).total_seconds() < 15*60:
print('station was updated:',st.__url__)
print(st.time(),st.ID(),st.temp(),st.humidity(),st.pressure())
sleep(15*60)
In [41]:
dt.datetime.now(dt.timezone.utc)
Out[41]:
In [30]:
dir(reference.LocalTimezone())
Out[30]:
In [ ]:
tm = parsedate_to_datetime('Tue, 27 Jun 2017 10:00:00 -0400')
tm2 = parsedate_to_datetime('Tue, 27 Jun 2017 10:00:00 -0400')
In [ ]:
(tm-tm2).total_seconds()
In [ ]:
#check for new data every 15 minutes
while True:
for st in stations:
st.update()
#check weather the sation's data was updated within the last 15 minutes
if (dt.datetime.now(dt.timezone.utc) - st.time()).total_seconds() < 15*60:
print('station was updated:',st.__url__)
print(st.temp(),st.humidity(),st.pressure(),st.time())
#average times
#cumparams=[0,0,0]
#total_stations = 0
#for st in stations:
# cumparams = [new+old for new,old in zip(cumparams,(st.temp(),st.humidity(),st.pressure()))]
# total_stations += 1
#avgparams = [x/total_stations for x in cumparams]
#print(dt.datetime.now(dt.timezone.utc),avgparams)
#or write to different files instead
sleep(15*60)
In [ ]:
print('hello world')
In [ ]: