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 :)