import time import smtplib from email.MIMEText import MIMEText from datetime import date, timedelta
import amara
#The base URI for all tags TAGBASE = ‘http://del./tag/‘
#Set FEEDS to customize which feeds you want to monitor FEEDS = [‘http://del./rss/uche‘, ‘http://del./rss/popular‘]
FROM = ‘del.@example.com‘ TO = ‘user@example.com‘ SMTPHOST = ‘localhost‘
#Compute the date string for yesterday in ISO-8601 format yesterday = (date(*time.gmtime()[:3]) - timedelta(1)).isoformat()
message_text = u‘‘
#Using Amara. Easy to just grab the RSS feed for feed in FEEDS: doc = amara.parse(feed) message_text += u‘\n‘ + unicode(doc.RDF.channel.title) + u‘\n\n‘ current_items = [ item for item in doc.RDF.item if unicode(item.date).startswith(yesterday) ] for item in current_items: #Get the properties of the link, defaulting to empty string title = unicode(getattr(item, ‘title‘, u‘‘)) href = unicode(getattr(item, ‘link‘, u‘‘)) desc = unicode(getattr(item, ‘description‘, u‘‘)) creator = unicode(getattr(item, ‘creator‘, u‘‘)) message_text += u‘<%s>--"%s" (from %s)\n‘%(href, title, creator) message_text += desc + ‘\n‘
#Be sure to handle Unicode by encoding to UTF-8 msg = MIMEText(message_text.encode(‘utf-8‘))
#Set message metadata msg[‘Subject‘] = u‘del. bookmarks for %s\n‘ % yesterday msg[‘From‘] = FROM msg[‘To‘] = TO
#Send the message via the specified SMTP server s = smtplib.SMTP() s.connect(SMTPHOST) #s.login(SMTP_USERNAME, SMTP_PASSWORD) #If login is necessary s.sendmail(FROM, [TO], msg.as_string()) s.close()
|