Subversion Repositories SmartDukaan

Rev

Rev 14635 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14635 Rev 14667
Line 3... Line 3...
3
from dtr.storage.MemCache import MemCache
3
from dtr.storage.MemCache import MemCache
4
mc = MemCache("127.0.0.1")
4
mc = MemCache("127.0.0.1")
5
 
5
 
6
class CricbuzzParser():
6
class CricbuzzParser():
7
    
7
    
8
    def __init__(self):
8
    def __init__(self, matchId):
9
        pass
9
        self.matchId = matchId 
10
       
10
       
11
    def getXml(self,matchId):
11
    def getXml(self):
12
        f = urllib2.urlopen("http://synd.cricbuzz.com/j2me/1.0/livematches.xml")
12
        f = urllib2.urlopen("http://synd.cricbuzz.com/j2me/1.0/livematches.xml")
13
        doc = xml.dom.minidom.parse(f)
13
        doc = xml.dom.minidom.parse(f)
14
        node = doc.documentElement
14
        node = doc.documentElement
15
        matches = node.getElementsByTagName("match")
15
        matches = node.getElementsByTagName("match")
16
        for match in matches:
16
        for match in matches:
17
            if matchId ==int(match.getAttribute('id')):
17
            if self.matchId ==int(match.getAttribute('id')):
18
                self.getMatchDetails(match)
18
                self.getMatchDetails(match)
19
    
19
    
20
    def getMatchDetails(self,match):
20
    def getMatchDetails(self,match):
21
        matchDesc = match.getAttribute("mchDesc")
21
        matchDesc = match.getAttribute("mchDesc")
22
        states = match.getElementsByTagName("state")
22
        states = match.getElementsByTagName("state")
Line 45... Line 45...
45
        except:
45
        except:
46
            battingTeamRuns = ""
46
            battingTeamRuns = ""
47
            battingTeamOvers = ""  
47
            battingTeamOvers = ""  
48
            battingTeamWickets = ""
48
            battingTeamWickets = ""
49
            battingTeamName = ""
49
            battingTeamName = ""
50
        result = {'matchDesc':matchDesc,'status':status,'mstate':mstate,'battingTeamName':battingTeamName,'battingTeamRuns':battingTeamRuns, \
50
        result = {'id':self.matchId,'matchDesc':matchDesc,'status':status,'mstate':mstate,'battingTeamName':battingTeamName,'battingTeamRuns':battingTeamRuns, \
51
         'battingTeamOvers':battingTeamOvers,'battingTeamWickets':battingTeamWickets}
51
         'battingTeamOvers':battingTeamOvers,'battingTeamWickets':battingTeamWickets}
52
        mc.set('liveScore', result)
52
        mc.set('liveScore', result)
53
        print result
53
        print result
54
        
54
        
55
if __name__ == '__main__':
55
if __name__ == '__main__':
56
    cric = CricbuzzParser()
56
    cric = CricbuzzParser(3)
57
    matches = cric.getXml(2)
57
    matches = cric.getXml()
58
    
58