| 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 |
|
| 14667 |
kshitij.so |
8 |
def __init__(self, matchId):
|
|
|
9 |
self.matchId = matchId
|
| 14619 |
kshitij.so |
10 |
|
| 14667 |
kshitij.so |
11 |
def getXml(self):
|
| 14619 |
kshitij.so |
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:
|
| 14667 |
kshitij.so |
17 |
if self.matchId ==int(match.getAttribute('id')):
|
| 14619 |
kshitij.so |
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:
|
| 14621 |
kshitij.so |
28 |
battingTeamName = battingTeamDesc.getAttribute('sName')
|
| 14622 |
kshitij.so |
29 |
try:
|
|
|
30 |
battingTeamInn = battingTeam[0].getElementsByTagName("Inngs")
|
|
|
31 |
for battingTeamInnDesc in battingTeamInn:
|
|
|
32 |
battingTeamRuns = battingTeamInnDesc.getAttribute('r')
|
|
|
33 |
battingTeamOvers = battingTeamInnDesc.getAttribute('ovrs')
|
|
|
34 |
battingTeamWickets = battingTeamInnDesc.getAttribute('wkts')
|
| 14619 |
kshitij.so |
35 |
|
| 14622 |
kshitij.so |
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 |
except:
|
|
|
46 |
battingTeamRuns = ""
|
|
|
47 |
battingTeamOvers = ""
|
|
|
48 |
battingTeamWickets = ""
|
|
|
49 |
battingTeamName = ""
|
| 14667 |
kshitij.so |
50 |
result = {'id':self.matchId,'matchDesc':matchDesc,'status':status,'mstate':mstate,'battingTeamName':battingTeamName,'battingTeamRuns':battingTeamRuns, \
|
| 14619 |
kshitij.so |
51 |
'battingTeamOvers':battingTeamOvers,'battingTeamWickets':battingTeamWickets}
|
|
|
52 |
mc.set('liveScore', result)
|
| 14621 |
kshitij.so |
53 |
print result
|
| 14619 |
kshitij.so |
54 |
|
|
|
55 |
if __name__ == '__main__':
|
| 14667 |
kshitij.so |
56 |
cric = CricbuzzParser(3)
|
|
|
57 |
matches = cric.getXml()
|
| 14619 |
kshitij.so |
58 |
|