Hi,
Have adapted some code I found on the net to get a rss feed from a news site. I would like to email the output of this script using smtplib - after a couple of frustrating hours I have got that working as a separate element with my gmail account.
In order to email the output of the code below, do I need to save the output as a text file?
Have done some googling and from what I can gather the answer lies with redirecting the sys.__stdout__ by assigning a writable object, but having some trouble understanding how to do that. Is that the way it should be done, or have I got the wrong idea entirely?
NB: For those that haven't guessed, I'm an absolute beginner; started playing with Python a few days ago and loving it so far!
Blair
import urllib
import sys
import xml.dom.minidom
#The url of the feed
address = 'http://www.stuff.co.nz/rss/'
#Our actual xml document
document = xml.dom.minidom.parse(urllib.urlopen(address))
for item in document.getElementsByTagName('item'):
title = item.getElementsByTagName('title')[0].firstChild.data
link = item.getElementsByTagName('link')[0].firstChild.data
description = item.getElementsByTagName('description')[0].firstChild.data
print '''<a href="%s">%s</a> (%s)''' % (link.encode('UTF8', 'replace'),
title.encode('UTF8','replace'),
description.encode('UTF8','replace'))