Commits

Gaurav Toshniwal committed 91511b0

Cricalarm files hosted

Comments (0)

Files changed (2)

+<?xml version="1.0" ?>
+<Matchdetail Awayteam="New Zealand" Awayteam_Id="5" Event="New Zealand in West Indies, 2 Test Series, 2012" Hometeam="West Indies" Hometeam_Id="9" LastUpdateddate="7/30/2012" LastUpdatedtime="1:56:56 AM" Match_Id="92854" Venue="Sir Vivian Richards Stadium, Antigua" currentinning="Fourth">
+  <Currentinnings>
+    <FOIEquation Bowlersused="" Overs="19.3" Runrate="5.23" Total="102" Wickets="1"/>
+    <Currentbatsmen>
+      <Currentbatsman BallsFaced="49" Batsman_Id="1201" Runs="64">
+        
+Chris Gayle
+            
+      </Currentbatsman>
+      <Currentbatsman BallsFaced="21" Batsman_Id="11688" Runs="7">
+        
+Assad Fudadin
+            
+      </Currentbatsman>
+    </Currentbatsmen>
+    <Currentbowlers>
+      
+    </Currentbowlers>
+  </Currentinnings>
+</Matchdetail>
+from bs4 import BeautifulSoup
+from xml.dom.minidom import Document
+import unicodedata
+
+#set the arrays of required attributes
+Matchdetail_attrs = ['Awayteam','Awayteam_Id','Event','Hometeam','Hometeam_Id','LastUpdateddate','LastUpdatedtime','Match_Id','Venue','currentinning']
+Currentinnings_attrs = ['AllottedOvers','Battingteam','Battingteam_Id','Bowlingteam','Bowlingteam_Id','Target']
+FOIEquation_attrs = ['Bowlersused','Overs','Runrate','Total','Wickets']
+batsman_attrs=['BallsFaced','Batsman_Id','Runs']
+
+soup = BeautifulSoup(open('recaserverxmlparsing/winzt17252012.xml'),'xml')
+
+matchdetail = soup.findAll('Matchdetail')
+
+current_inning_key = {
+	'First' : 'FI',
+	'Second': 'SI',
+	'Third' : 'TI',
+	'Fourth': 'FOI',
+}
+batsmen = soup.findAll(current_inning_key[matchdetail[0]['currentinning']]+'Batsman',Howout='not out')
+soup.findAll(Bowling="Yes")
+
+#create xml document structure
+doc = Document()
+Matchdetail = doc.createElement("Matchdetail")
+doc.appendChild(Matchdetail)
+for attr in Matchdetail_attrs:
+	Matchdetail.setAttribute(attr,matchdetail[0][attr])
+
+Currentinnings = doc.createElement("Currentinnings")
+Matchdetail.appendChild(Currentinnings)
+
+foiequation = soup.findAll('FOIEquation')
+FOIEquation = doc.createElement("FOIEquation")
+Currentinnings.appendChild(FOIEquation)
+for attr in FOIEquation_attrs:
+	FOIEquation.setAttribute(attr,foiequation[0][attr])
+
+Currentbatsmen = doc.createElement("Currentbatsmen")
+Currentinnings.appendChild(Currentbatsmen)
+
+for batsman in batsmen:
+	Currentbatsman = doc.createElement('Currentbatsman')
+	for attr in batsman_attrs:
+		Currentbatsman.setAttribute(attr,batsman[attr])
+	Currentbatsmen.appendChild(Currentbatsman)
+	Currentbatsman.appendChild(doc.createTextNode(batsman.contents[0].encode('ascii','ignore')))
+
+Currentbowlers = doc.createElement("Currentbowlers")
+Currentinnings.appendChild(Currentbowlers)
+Currentbowlers.appendChild(doc.createTextNode(''))
+
+f=open('score.xml','w')
+f.write(doc.toprettyxml(indent="  "))
+f.close()
+print doc.toprettyxml(indent="  ")