I wanted to create a twitter feed of things my daughters were doing with the goal of easily updating the grandparents on what they were doing. Now, they aren't twitter users but I use twitter enough that it was an easy medium. I wrote a little python script that runs every few minutes and emails them the updates.
I know there are tools out there that turn RSS into email, but that would require that I know all the account credentials, which wasn't desired. Since this is a known audience, I don't have to worry about opt out so I can just use direct email method. Below is the source code so please use if you want and as always, feel free to comment.
#!/usr/bin/python ########################################################################################################## # tweetMail.py # File created to enable simple emailing of twitter feed. Good for emailing to people who don't use # Twitter and/or cannot use an RSS reader. # Author: Mike Dunphy # License: This is script is released into the public domain with no guarantee or waranty of any kind. # please use at your own discretion and/or peril ########################################################################################################## import sys,smtplib sys.path.append('/home/miked/feedparse') # FeedParser module location for share hosting import feedparser def send_mail(message): smtpObj = smtplib.SMTP('localhost') sender = 'email@address.com' #From address of emails receivers = ['email@address.com'] #Multiple addresses seperated by commas smtpObj.sendmail(sender,receivers,message) smtpObj.quit() FILEPATH = '/path/to/file' #This file keeps track of last twitter uid feed = feedparser.parse("Twitter URL goes here") #Remember that if the account is protected add credentials f = open(FILEPATH) lastvalue = int(f.readline()) f.close() for entry in feed.entries: if (int(entry.id[40:]) > int(lastvalue)): #This is ugly but 40 characters chops the URL leaving just #the twitter uid. Change this to fit your feed. #The message headers repeat to section one address per line. Can add CC: entries too #Reply-To section defines a reply-to address if you don't want replies sent to sender address message1 = """From: From Address <email@address.com> To: To address <email@address.com> Reply-To: <email@address.com> Subject: Message Subject """ message2 = entry.summary[13:] #Again, this is ugly but the [13:] chops the username out of the summary. Change for your use message = message1 + '\n' + message2 send_mail(message) f = open(FILEPATH,'w') f.write(feed.entries[0].id[40:]) f.close()
