Get all this summer’s cricket action – via twitter!
Are you a Australian? Are you a cricket fan? Are you on twitter? If you answered yes to all of these questions, you might be interested in the Twitter bot that I just coded up. Using the fantastic cricinfo.com website, some Hpricot trickery, the Twitter gem and some Ruby jiggery pokery you can get a ball-by-ball commentary of the Aussies beating everyone in there path.
So head over to http://twitter.com/baggygreen and get your summer cricket fix!
How it works:
- I used the WAP version of the cricinfo website, because the HTML is much simpler to deal with. First I find all games that Australia are playing. The front page has a list all all games in progress. Doing a string comparision, I grab the URLs to any Australian games.
- Using Hpricot, I parse the HTML from the commentary page, pulling out the score, overs, balls and commentary using X-path.
- I keep track of what I’ve already posted in a text file. Any new comments are posted to Twitter. If the script detects the end of an over, the score is posted as well.
- The script runs as a crob job every 5 minutes
Nice an easy, eh?
Update: Download the code! Excuse it’s less than optimal solution – it was hastily written :)
10 comments
I'm sure there is a number of optimisations that can be made, but this was more of a quick hack to prove a point :)
A nice piece of making the most out of desirable source content and a cool distribution mechanism.
More power to you.
Thanks
James
Yep - that should work. You might want to check cricinfo (look at the firl URL that is in the code) and see what the exact string for England is.
Thanks James
If gems isn't installed already, try googling it for your platform, to find the best way to install, then:
gem install open-uri
gem install hpricot
gem install twitter
should do it.
Leave a comment