import urllib
 
class Score(object):
     
    """"Parses the score from score file"""
     
    SCORE_URL = "<this should be the URL of score file>"
     
    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)s - %(message)s - %(tagline)s" % self.vars
         
         
class RediffScore(Score):
 
    """Data from www.rediff.com"""
    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']
         
 
if __name__ == '__main__':
#    print 'Current score'
    sc = RediffScore()
    sc.refresh()
    print sc.render()
