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())


2017-07-10 15:51:00-04:00 KNYC 82.0 56.0 1015.7
2017-07-10 15:51:00-04:00 KLGA 84.0 55.0 1015.7
2017-07-10 20:15:00+00:00 KJRB 84.0 55.0 1030.0
2017-07-10 15:51:00-04:00 KJFK 80.0 69.0 1016.6

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)


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-6-89aafe0bd5d8> in <module>()
     11 
     12 
---> 13     sleep(15*60)

KeyboardInterrupt: 

In [41]:
dt.datetime.now(dt.timezone.utc)


Out[41]:
datetime.datetime(2017, 6, 28, 16, 59, 8, 269415, tzinfo=datetime.timezone.utc)

In [30]:
dir(reference.LocalTimezone())


Out[30]:
['__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_isdst',
 'dst',
 'fromutc',
 'tzname',
 'utcoffset']

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 [ ]: