3
0

BuildModFiles.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python3
  2. import os
  3. import fileinput
  4. import re
  5. import sys
  6. modTag = "mod"
  7. file_path_html = 'glife.html'
  8. file_path_mod = 'mod.html'
  9. file_path_mod_online = 'mod.php'
  10. data = ''
  11. modData = ''
  12. scripts = ''
  13. dataWithoutModStuff = ''
  14. with open(file_path_html, 'r') as file:
  15. data = file.read()
  16. dataWithoutModStuff = data
  17. i = 0
  18. regex = r"""<tw-passagedata pid="(\d+)" name="([\s\w]+)" tags="(.*?)" (?:position="\d+,\d+" )?(?:size="\d+,\d+")?>(.*?)</tw-passagedata>"""
  19. for match in re.finditer(regex,data,re.S):
  20. tags = match.group(3).split()
  21. if(modTag in tags):
  22. modData += match.group(0)+'\n'
  23. dataWithoutModStuff = dataWithoutModStuff.replace(match.group(0),'')
  24. i += 1
  25. if(i % 100 == 0):
  26. print(i)
  27. regex = r"""/\*\s*Start Mod:\s*"Mod"\s*\*/(.*?)/\*\s*End Mod:\s*"Mod"\s*\*/"""
  28. for match in re.finditer(regex,data,re.S):
  29. scripts += match.group(1)
  30. dataWithoutModStuff = dataWithoutModStuff.replace(match.group(0),'')
  31. modData += "\n.-.-.-. STORYDATA / SCRIPT .-.-.-.\n"
  32. modData += scripts
  33. with open(file_path_mod, 'w') as file:
  34. file.write(modData)
  35. with open(file_path_mod_online, 'w') as file:
  36. file.write(f'<?php header("Access-Control-Allow-Origin: *"); header(\'Content-type: text/javascript\'); echo($_GET[\'callback\']);?>(`{modData}\n`);')
  37. with open(file_path_html, 'w') as file:
  38. file.write(dataWithoutModStuff)
  39. print('Done')