Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. from pprint import pprint
  2.  
  3. filedata = ("""<codec freq="140.15">
  4.    <face actor="SOLID SNAKE" image="f73b"></face>
  5.    <face actor="MERYL SILVERBURGH" image="7702"></face>
  6.    <face actor="MERYL SILVERBURGH" image="7d66"></face>
  7.    <voice hash="3d43">
  8.        <text actor="MERYL SILVERBURGH" face="39c3">Be careful, Snake. That air lock is set with infrared sensors.</text>
  9.    </voice>
  10.    <if condition="02:0 IsZero writeVAR[01009c]">
  11.        <voice hash="3d5a">
  12.            <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>
  13.            <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>
  14.            <text actor="MERYL SILVERBURGH" face="39c3">Somehow, you've got to get through without setting off those sensors.</text>
  15.        </voice>
  16.        <set math="writeVAR[01009c] = 02:1"></set>
  17.    </if>
  18.  
  19.    <face actor="MERYL SILVERBURGH" image="6d84"></face>
  20. </codec>""" )
  21.  
  22. def clean(filedata): # Receives codec filedata, removes tabs and empty lines, then returns list of lines.
  23.     filedata = filedata.replace("\t", "")
  24.     filedata = filedata.replace("\n\n", "\n")
  25.  
  26.     return filedata.splitlines() # returning as intended (text and number of lines)
  27.  
  28.  
  29. def getLineID(Line):
  30.     Line = Line.lstrip(' ')
  31.     LineId = Line[Line.find('<')+1:Line.find(' ')]
  32.  
  33.     return LineId
  34.  
  35. def getLineAttr(Line):
  36.     Line = Line.lstrip(' ')
  37.     LineAttr = []
  38.  
  39.     for Lina in Line.split(' '):
  40.         if Lina.find('"') != -1:
  41.             Lina.replace('"', '')
  42.             LineAttr.append({
  43.                 Lina.replace('=', ':')
  44.             })
  45.    
  46.     return LineAttr
  47.  
  48. testCode = clean(filedata)
  49. dick = []
  50.  
  51. for testLine in testCode:
  52.     a = []
  53.     a.append(getLineID(testLine))
  54.     a.append(getLineAttr(testLine))
  55.     dick.append(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement