Saturday, January 16, 2010

Talk Like Warren Ellis (@talklikewarren)

I am a fan of author Warren Ellis. He writes comics like Doktor Sleepless (see left) which has some interesting information warfare themes along with mad science and you should all check it out. Doktor Sleepless incidentally, is where I stole the cool warning signs that grace my first couple of entries here. Warren Ellis is a strange, strange man. He has a very popular twitter account (over 300,000 followers) where he does the usual twitter things but in addition he makes exclamations like "Good morning lovemaggots" and "ATTENTION SCUM: You’re obviously all terrible people".

Scott Vandehey and Miles Johnson were so thrilled by these exclamations they decided to see if they could recreate Warren Ellis like sayings programmatically. Thus talklikewarrenellis.com was born, it's a nice simple web site that will give you a Warren Ellisesque exclamation every time you visit, it'll even give you a link to a screen reading service that will pronounce it for you. The magic that powers this is a Warren Ellis grammar that was created using an inverse parser on a large set of Warren Ellis' exclamations. To the right is a graph for an Extended Backus-Naur Format grammar. The whole thing is really interesting and you should go to Miles' blog and read about it here.

I was so impressed that I decided that I wanted a mechanism that would occasionally show me one of the generated exclamations. I decided that twitter would be a good vehicle and wrote a little script that would scrape an exclamation and post it to @talklikewarren. Here's the code:

#!/usr/bin/env python
import twitter, urllib2, time, re, random
random.seed()

while (True):
    try:
        page = urllib2.urlopen('http://talklikewarrenellis.com/').read()
        post = re.search("<h1>(.*)</h1>", page, re.M).group(1)
        print post
        api = twitter.Twitter("USERNAME", "PASSWORD")
        api.statuses.update(status = post)
        print "success"
    except Exception:
        pass
    sleepinterval = random.randrange(30,6*60)
    print "Sleeping for %d minutes" % sleepinterval
    time.sleep(60 * sleepinterval)
 
Obviously this snippet isn't ground breaking but I wanted to post another example of using Mike Verdon’s Python Twitter Tools.

No comments:

Post a Comment