Get all this summer’s cricket action - via twitter!
20
Nov
Tags: twitter, ruby on rails
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 ![]()












November 21st, 2007 at 7:15 am
[…] go here to see how, Warney-like, Myles weaves his […]
November 21st, 2007 at 12:11 pm
and the source code ? would be great to have it for download people could use it for other countries too .
November 21st, 2007 at 12:23 pm
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
November 21st, 2007 at 12:43 pm
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.
November 25th, 2007 at 3:30 pm
[…] from Myles ,but his work was in ruby and i dont know much of it and iam lot comfortable with python […]
January 24th, 2008 at 2:51 pm
love it! 2hr train ride cricketless is torture… just wish i found it 3 test matches ago…
April 3rd, 2009 at 12:39 am
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
April 3rd, 2009 at 7:20 am
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.
April 3rd, 2009 at 9:43 pm
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
April 6th, 2009 at 11:58 am
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.