Advertisement
skaianDestiny

GFL Story Script Converter

Nov 18th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. # GFL story script editor by skaianDestiny
  2. # 11-18-2019
  3. #
  4. # converts raw GFL script text files into a format for the wiki
  5. # minor edits required for the output, but the majority of the work is done
  6. # if an argument is passed, then the user is prompted for the text file name
  7. # if no argument is passed, then the text is taken from 'script.html'
  8.  
  9. import re
  10. import sys
  11. from pathlib import Path
  12.  
  13. def debugLineError(lines):
  14. for i, l in enumerate(lines):
  15. print(l)
  16. if names[i] != '':
  17. l = re.sub(r'.*?>' + names[i] + '<.*?:', names[i] + ': ', l)
  18. else:
  19. l = re.sub(r'.*?:', names[i] + '[', l)
  20.  
  21. output = "script_trimmed.html"
  22.  
  23. #for manual input
  24. if len(sys.argv) > 1:
  25. folder = Path('avgtxt/')
  26. textfile = input('Enter text file name: ') + '.txt'
  27. source = folder / textfile
  28. else:
  29. source = "script.html"
  30.  
  31. lines = list()
  32.  
  33. with open(source, encoding = 'utf-8') as fp:
  34. line = fp.readline()
  35. while line:
  36. lines.append(line.strip())
  37. line = fp.readline()
  38.  
  39. names = [re.search('<Speaker>(.*)</Speaker>', l, re.IGNORECASE).group(1) if re.search('<Speaker>(.*)</Speaker>', l, re.IGNORECASE) else '' for l in lines]
  40.  
  41. # debugLineError(lines)
  42.  
  43. #cleans all those dirty dialogue tags
  44. lines = [re.sub(r'.*?>' + names[i] + '<.*?:', names[i] + ': ', l) if names[i] != '' else re.sub(r'.*?:', names[i] + '[', l) for i, l in enumerate(lines)]
  45. #adds the multi line dialogue
  46. lines = [re.sub(r'\+', '<br>\n', l) for l in lines]
  47. #adds the extra linebreak
  48. lines = [l + '<br>\n' for l in lines]
  49.  
  50. with open(output, 'w', encoding = 'utf-8') as file:
  51. for l in lines:
  52. file.write(l + '<br>\n')
  53. print(l)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement