Playing with Weather

https://openweathermap.org/api


In [ ]:
import pyowm                   # Open Weather Map from Google 
import smtplib                 # sending email/SMS
from datetime import datetime
from dateutil.tz import tz, tzlocal

In [ ]:
## Setup the variables to play with Current Weather 
### owm is the object to access all weather info 
### forecast is an observation  object the day's forecast for Durham NC

In [ ]:
owm = pyowm.OWM('DELETED') # Plant Key from https://home.openweathermap.org/api_keys
print(owm)

In [ ]:
DURM = 4464368
forecast = owm.weather_at_id(DURM)
print(forecast)
time = forecast.get_reception_time(timeformat='date')
print('GMT time: ',time)
print('EST Time:', time.astimezone(tzlocal()))           # make EST instead of GMT

In [ ]:
weather = forecast.get_weather()
print('temperature: ',weather.get_temperature('fahrenheit')['temp'])
print('Detailed Status: ',weather.get_detailed_status())
sunset = weather.get_sunset_time(timeformat='date').astimezone(tzlocal())
print('Sunset Time: ', sunset.hour-12, ':',str(sunset.minute).rjust(2,'0'))
print('Wind = ', weather.get_wind()['speed'])
# todo: remove date

In [ ]:
fc = owm.daily_forecast('Durham,us',limit=3)
f = fc.get_forecast()
lst = f.get_weathers()
for weather in f: 
    print(weather.get_reference_time('iso'), weather.get_temperature('fahrenheit')['min'])

In [ ]:
today_forecast = owm.daily_forecast('Durham, us', limit=1).get_forecast().get_weathers()[0].get_temperature('fahrenheit')['min']
print(today_forecast)

Playing with SMS


In [ ]:

Below are scraps


In [ ]:
registry = owm.city_id_registry()

In [ ]:
print(registry.location_for("Milan, it"))

In [ ]:
print(registry)

In [ ]:
obs = owm.weather_at_place('Durham, us')

In [ ]:
w = obs.get_weather()

In [ ]:
print(w)

In [ ]:
print(obs)

In [ ]:
print(w.get_temperature('fahrenheit'))
fc=owm.daily_forecast('Durham, us')
print(fc.get_forecast().get_weathers())

In [ ]:
l = obs.get_location()

In [ ]:
print(l)

In [ ]:


In [ ]:
from email.mime.text import MIMEText
import smtplib

In [ ]:
with open('temp.txt') as fp: 
    msg = MIMEText(fp.read())
msg['Subject'] = 'Ginny Test of Email'
me = 'ginnyghezzo@gmail.com'
msg['From'] = me
msg['To'] = me
s = smtplib.SMTP('smtp.gmail.com', 587)
s.ehlo()
s.starttls()
s.login(me, 'cpgqqsorhfretpmt')
s.sendmail(me, [me],msg.as_string())
s.quit()

Sending a Text

Need to setup as


In [ ]:
from twilio.rest import TwilioRestClient

In [ ]:
accountSID = 'Deleted'
authToken = 'Deleted'
twilioCli = TwilioRestClient(accountSID, authToken)
myTwilioNum = '+removed'
myCellPhone = '+redacted'
bodies="Thursday Phoenix arrival  49.19 Thursday Sedona  45.0 Friday Sedona  41.61 to 45.54 Friday Grand Canyon  41.56 to 29.82 Saturday Grand Canyon  27.88 to 32.83 31.19 to 13.59 Sunday Grand Canyon  14.59 to 29.55 Sunday Phoenix  49.55 to 41.63 Monday Phoneix  36.55 to 49.24"
msg = twilioCli.messages.create(to=myCellPhone, from_=myTwilioNum,  body=bodies)

In [ ]:
print(msg)

Charting Weather with Bokeh


In [ ]: