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

Categories

,

About this Entry

This page contains a single entry by James published on September 11, 2009 11:22 AM.

Berkey Light Water Filter Review was the previous entry in this blog.

Testing BH is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 5.04