Subversion Repositories SmartDukaan

Rev

Rev 14621 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14619 kshitij.so 1
import xml.dom.minidom
2
import urllib2
3
from dtr.storage.MemCache import MemCache
4
mc = MemCache("127.0.0.1")
5
 
6
class CricbuzzParser():
7
 
8
    def __init__(self):
9
        pass
10
 
11
    def getXml(self,matchId):
12
        f = urllib2.urlopen("http://synd.cricbuzz.com/j2me/1.0/livematches.xml")
13
        doc = xml.dom.minidom.parse(f)
14
        node = doc.documentElement
15
        matches = node.getElementsByTagName("match")
16
        for match in matches:
17
            if matchId ==int(match.getAttribute('id')):
18
                self.getMatchDetails(match)
19
 
20
    def getMatchDetails(self,match):
21
        matchDesc = match.getAttribute("mchDesc")
22
        states = match.getElementsByTagName("state")
23
        for state in states:
24
            status = state.getAttribute("status")
25
            mstate = state.getAttribute('mchState')
26
        battingTeam = match.getElementsByTagName("btTm")
27
        for battingTeamDesc in battingTeam:
28
            battingTeam = battingTeamDesc.getAttribute('sName')
29
 
30
        battingTeamInn = match.getElementsByTagName("Inngs")
31
        for battingTeamInnDesc in battingTeamInn: 
32
            battingTeamRuns = battingTeamInnDesc.getAttribute('r')
33
            battingTeamOvers =  battingTeamInnDesc.getAttribute('ovrs')
34
            battingTeamWickets =  battingTeamInnDesc.getAttribute('wkts')
35
 
36
        bowlingTeam = match.getElementsByTagName("blgTm")
37
        for bowlingTeamDesc in bowlingTeam:
38
            bowlingTeam = bowlingTeamDesc.getAttribute('sName')
39
 
40
        bowlingTeamInn = match.getElementsByTagName("blgTm")
41
        for bowlingTeamInnDesc in bowlingTeamInn:
42
            print bowlingTeamInnDesc.getAttribute('r')
43
            print bowlingTeamInnDesc.getAttribute('ovrs')
44
            print bowlingTeamInnDesc.getAttribute('wkts')
45
 
46
        result = {'matchDesc':matchDesc,'status':status,'mstate':mstate,'battingTeam':battingTeam,'battingTeamRuns':battingTeamRuns, \
47
         'battingTeamOvers':battingTeamOvers,'battingTeamWickets':battingTeamWickets}
48
        mc.set('liveScore', result)
49
 
50
if __name__ == '__main__':
51
    cric = CricbuzzParser()
52
    matches = cric.getXml(1)
53