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

10 comments

  1. Pingback: Web Directions South 2007 » Blog Archive » Cricket action via twitter
  2. and the source code ? would be great to have it for download people could use it for other countries too .
  3. Your wish is my command husty - you can download the source at the bottom of the post.



    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 :)
  4. And the point is well proved, Myles.



    A nice piece of making the most out of desirable source content and a cool distribution mechanism.



    More power to you.
  5. Pingback: » cricket action on twitter » word of the worlds
  6. love it! 2hr train ride cricketless is torture... just wish i found it 3 test matches ago...
  7. I've been looking for an app like this for awhile, but for england, not australia, is it just a case of altering the keyword australia to england? and then re-compiling? I havn't used ruby before.



    Thanks

    James
  8. Hi 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.
  9. Sorry to be a pain, but is the cricinfo.rb file the only file i need to get this to work on my server?



    Thanks James
  10. You'll need the rubygems, open-uri and hpricot and twitter gems



    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