Animesh Kumar {itsAnimesh}

Animesh Kumar {itsAnimesh}

I'm an IT professional from New Delhi, India. Currently for the most part I work as a Technical Consultant developing Open Source ICT solutions for social and societal inclusion. I'm also pursing PG in Management. Below are the latest updates from a some social networks I subscribe to.

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

Thanks for Reading... Please Post Your Comments Below

  1. Amit Bhardwaj says:

    hi animesh
    thankz for script as IPL an exams are clashing and cant watch live on t.v.
    but got error
    abc@abc-desktop:~$ python cric_score.py
    File “cric_score.py”, line 3
    SCORE_URL = “”
    ^
    IndentationError: expected an indented block

    dont know any thing about .py

  2. Amit Bhardwaj says:

    google solved my problem.
    you have to indent this code, i have done it like this correct me if i am not.

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

    but still giving error:

    File “cric_score.py”, line 13
    if stmt == “”: continue
    SyntaxError: ‘continue’ not properly in loop

  3. Alright I got it uploaded on Box.net..
    Here is the link..
    http://www.box.net/shared/uu203jgou0

  4. [...] This is a python script with tkinter to get cricket score. I got this script from my from animesh’s blog. I have just modified the script to provide output on a screen rather then on [...]

  5. Amit Bhardwaj says:

    i have made some changes in the script
    http://bamit0890.wordpress.com/2009/04/19/live-cricket-score/

  6. hemanth says:

    How to know if its second half or first half and how to know the total chasing if it’s the second half ?

  7. azhar shaikh says:

    hey whatz up?

  8. MAHESH BABU says:

    hai animesh how are you i am the student of iiit ..I Think you are very good programmer .Thank you for up loding this programme .

    plz uplode me coding for cricket game ..thank you ..bye….bye…..
    YOU ARE VERY NICE YAAAA

  9. MAHESH BABU says:

    THROUGH MY EMAIL ID
    mahesh.atp.dmm@gmail.com

  10. Theres a problem with the script i think.. Anyways heres a link to where i have uploaded my script download it from here extract it and try.. I wasn’t able to upload it on box.net so its on rapidshare… http://rapidshare.com/files/222849291/score.zip.html

  11. This script actually uses this text file from rediff http://livechat.rediff.com/sports/score/score.txt . The only limitation is that what ever is written in this text file can only be used..