MakeMod.py 865 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 = 'mods/mod.html'
  9. data = ''
  10. modData = ''
  11. scripts = ''
  12. with open(file_path_html, 'r') as file:
  13. data = file.read()
  14. i = 0
  15. regex = r"""<tw-passagedata pid="(\d+)" name="([\s\w]+)" tags="(.*?)" (?:position="\d+,\d+" )?(?:size="\d+,\d+")?>(.*?)</tw-passagedata>"""
  16. for match in re.finditer(regex,data,re.S):
  17. tags = match.group(3).split()
  18. if(modTag in tags):
  19. modData += match.group(0)+'\n'
  20. i += 1
  21. if(i % 100 == 0):
  22. print(i)
  23. regex = r"""/\*\s*Start Mod:\s*"Mod"\s*\*/(.*?)/\*\s*End Mod:\s*"Mod"\s*\*/"""
  24. for match in re.finditer(regex,data,re.S):
  25. scripts += match.group(1)
  26. modData += '<script>'+scripts+'</script>'
  27. with open(file_path_mod, 'w') as file:
  28. file.write(modData)
  29. print('Done')