Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pprint import pprint
- filedata = ("""<codec freq="140.15">
- <face actor="SOLID SNAKE" image="f73b"></face>
- <face actor="MERYL SILVERBURGH" image="7702"></face>
- <face actor="MERYL SILVERBURGH" image="7d66"></face>
- <voice hash="3d43">
- <text actor="MERYL SILVERBURGH" face="39c3">Be careful, Snake. That air lock is set with infrared sensors.</text>
- </voice>
- <if condition="02:0 IsZero writeVAR[01009c]">
- <voice hash="3d5a">
- <text actor="MERYL SILVERBURGH" face="39c3">You probably can't see them with your naked eyes, but there are infrared beams coming out of that wall.</text>
- <text actor="MERYL SILVERBURGH" face="39c3">Touch any one of them, and the doors will seal off and the place will be flooded with poison gas.</text>
- <text actor="MERYL SILVERBURGH" face="39c3">Somehow, you've got to get through without setting off those sensors.</text>
- </voice>
- <set math="writeVAR[01009c] = 02:1"></set>
- </if>
- <face actor="MERYL SILVERBURGH" image="6d84"></face>
- </codec>""" )
- def clean(filedata): # Receives codec filedata, removes tabs and empty lines, then returns list of lines.
- filedata = filedata.replace("\t", "")
- filedata = filedata.replace("\n\n", "\n")
- return filedata.splitlines() # returning as intended (text and number of lines)
- def getLineID(Line):
- Line = Line.lstrip(' ')
- LineId = Line[Line.find('<')+1:Line.find(' ')]
- return LineId
- def getLineAttr(Line):
- Line = Line.lstrip(' ')
- LineAttr = []
- for Lina in Line.split(' '):
- if Lina.find('"') != -1:
- Lina.replace('"', '')
- LineAttr.append({
- Lina.replace('=', ':')
- })
- return LineAttr
- testCode = clean(filedata)
- dick = []
- for testLine in testCode:
- a = []
- a.append(getLineID(testLine))
- a.append(getLineAttr(testLine))
- dick.append(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement