@madpilot makes

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:

  1. 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.
  2. Using Hpricot, I parse the HTML from the commentary page, pulling out the score, overs, balls and commentary using X-path.
  3. 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.
  4. 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 :)