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:

import xml.etree.ElementTree as ET
import httplib
import smtplib
from email.mime.text import MIMEText

conn = httplib.HTTPConnection('')
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 = ''
    msg['To'] = to_addr = ''

    s = smtplib.SMTP('', 587)
    s.sendmail(from_addr, to_addr, msg.as_string())



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