Advertisement
qazmlpok

fix_dialogue.py

Jul 26th, 2014
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import os, sys
  2. import re
  3.  
  4. if len(sys.argv) < 2:
  5.     print 'USAGE:', sys.argv[0], "<Dialogue file name>"
  6.     exit()
  7.  
  8. filename = sys.argv[1]
  9. infile = open(filename)
  10. data = infile.readlines()
  11. infile.close()
  12.  
  13. outfile = open(filename, 'w')
  14. for line in data:
  15.     m = re.match('([0-9a-fA-F]{8}: )(.*)', line)
  16.     if not m:
  17.         outfile.write(line)
  18.     else:
  19.         addr = m.group(1)
  20.         line = m.group(2).strip('\n')
  21.  
  22.         outfile.write(addr)
  23.  
  24.         txt = line.split('@')
  25.         first = True
  26.         for x in txt:
  27.             if not first:
  28.                 outfile.write('@')  #I think this is the easiest way to put the @s back in
  29.             first = False
  30.  
  31.             outfile.write(x)
  32.             if len(x) % 2 == 1:
  33.                 outfile.write(' ')  #If there's already a space, it will add a second. Presumably the space was put in for readability.
  34.  
  35.         outfile.write('\n')
  36.  
  37. outfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement