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