Quote of the Day Tweeter

I wrote this to pull from QuotationsPage.com and post the quote of the day to twitter in Python. Download it, edit the username/password line and set it up in cron to run once a day.

Download Here

Source below:

#!/usr/bin/env python
# Copyright Josh Rendek 2009 bluescripts.net
# No liability blah blah use at your own risk, etc
from xml.dom.minidom import parseString
from urllib import urlopen
import re
import random
from os import popen
 
#specify user / pass
user = "USERNAME"
password = "PASSWORD"
 
#raw xml
xml = urlopen("http://feeds.feedburner.com/quotationspage/qotd").read()
 
#xml parsed
xp = parseString(xml)
quotes = []
qts = []
rss = xp.childNodes[2].childNodes[1]
for i in rss.childNodes:
	if i.localName == "item":
		quotes.append(i)
 
for q in quotes:
	for x in q.childNodes:
		if x.localName == "title":
			author = " - " + x.childNodes[0].nodeValue
		if x.localName == "description":
			quote = x.childNodes[0].nodeValue
			qt = re.search('".*"', quote)
			if len(qt.group(0)) + len(author) < 140:
				qts.append(qt.group(0).split('"')[1]+author)
quote_to_post = random.sample(qts, 1)
print quote_to_post[0]
 
 
url = 'http://twitter.com/statuses/update.xml'
curl = 'curl -s -u %s:%s -d status="%s" %s' % (user,password,quote_to_post[0],url)
p = popen(curl)
 
print "Done!"

Leave a Reply

© 2008 Josh Rendek.