Moving Planters indoors for Winter: Python Redux
After reading Moving Planters Indoors for the Winter by Joseph Hall I decided to translate his script to Python. Here's the result:
#!/usr/bin/python
import xml.etree.ElementTree as ET
import httplib
import smtplib
from email.mime.text import MIMEText
conn = httplib.HTTPConnection('www.wrh.noaa.gov')
conn.request('GET','/forecast/xml/xml.php?duration=168&interval=6&lat=40.69651&lon=-112.091784')
response = conn.getresponse()
forecast_xml = ET.parse(response)
low_temp = 100
for child in forecast_xml.getiterator():
if child.tag == 'temperature':
temp = int(child.text)
low_temp = temp if temp < low_temp else low_temp
if low_temp < 40:
msg = MIMEText('Temps as low as %s coming up' % low_temp)
msg['Subject'] = 'Cold Weather'
msg['From'] = from_addr = 'username@gmail.com'
msg['To'] = to_addr = '000000000@messaging.sprintpcs.com'
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login('username','password')
s.sendmail(from_addr, to_addr, msg.as_string())
s.quit()
0 TrackBacks
Listed below are links to blogs that reference this entry: Moving Planters indoors for Winter: Python Redux.
TrackBack URL for this entry: http://www.thelances.net/cgi-bin/mt/mt-tb.cgi/218

Leave a comment