Python Script for Cricket Score!!!

Here’s a script that i wrote to get the latest cricket score without visiting the site. It’s a python script that makes use of rediff scores.

import urllib
class Score(object):
SCORE_URL = ""
def __init__(self):
self.vars = {} # dictionary variables read from the score file
def refresh(self):
"""Refresh the score"""
url_opener = urllib.URLopener()
url = url_opener.open(self.SCORE_URL)
self.vars = {}
for stmt in url.read().split('n'):
stmt = stmt.strip()
if stmt == "": continue
var, val = stmt.split('=')
self.vars[var] = val
url.close()
return self.vars
def render(self):
"""Return the rendered text"""
return "%(l1)sn%(message)sn%(tagline)sn" % self.vars
class RediffScore(Score):
SCORE_URL = "http://livechat.rediff.com:80/sports/score/score.txt"
def getMatchName(self):
return self.vars['tagline']
def getScore(self):
return self.vars['l2']
def getTeams(self):
return self.vars['l1']
def getDate(self):
return self.vars['date']
def getMessage(self):
return self.vars['message']
def getInterval(self):
return self.vars['interval']
if __name__ == '__main__':
print 'Current score'
sc = RediffScore()
sc.refresh()
print sc.render()

Copy the script in a text editor and save it as score.py in your home folder.
Now run the script by :
animesh@animesh-laptop:~$ python score.py

The output should be somewhat like :
Current score
Australia vs New Zealand
Australia 181-10 (48.4)
S Tait(9)

Note: There is a problem with the script here.. i think when i copy pasted the file the indentation got messed up..
So here’s a link from where you can download it..
http://www.box.net/shared/uu203jgou0

If you face any problem please comment. :)