Tuesday, 2 March 2010

concerto + twitter

During the trials of concerto at CERN, I wanted to make the text fields a bit more dynamic like say following a specific twitter feed.

This would (ideally) simply consist of a DB entry with type=twitter, value=name of person. In the Real World however I got round this by hacking up a simple python script that connects to the DB and does a simple UPDATE of an existing text/plain entry via cron.

posted below incase others find it useful:

#!/usr/bin/python

# Script to pull twitter feeds for cern / lhcstatus
import twitter
import MySQLdb


conn = MySQLdb.connect (host = "...", user = "...", passwd = "...", db = "...")
api = twitter.Api()
feeds = { 'cern': 25, 'lhcstatus': 28 }
for f in feeds:
tweets = api.GetUserTimeline(f,count=1)
for tweet in tweets:
sql = 'UPDATE content SET CONTENT = "%s" WHERE id = %s' % (tweet.GetText(),feeds[f])
cursor = conn.cursor ()
try:
cursor.execute(sql)
conn.commit()
except:
conn.rollback()
cursor.close ()
conn.close ()


yes its hacky, but hey, called from cron regularly it works :-)

Monday, 1 March 2010

They're following me!


As you know, I've been 'tweeting' the Status of the LHC from the 'Page1 comments' field. Decided to knock up a quick script to plot the number of followers over time, and lo:

Word of mouth Skye History

Many years ago we lived in the Old Manse in Waternish, Skye. If you look on the maps, you'll spot that unlike nearly all the other house...