sugarcube_postCompile.py 865 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. import os
  3. import fileinput
  4. import re
  5. import sys
  6. file_path_html = 'glife.html'
  7. deprecatedTag = "deprecated"
  8. data = ''
  9. with open(file_path_html, 'r') as file:
  10. data = file.read()
  11. dataLengthInitial = len(data)
  12. dataWithoutDeprecated = data
  13. i = 0
  14. regex = r"""<tw-passagedata pid="(\d+)" name="([\s\w]+)" tags="(.*?)" (?:position="\d+,\d+" )?(?:size="\d+,\d+")?>(.*?)</tw-passagedata>"""
  15. for match in re.finditer(regex,data,re.S):
  16. tags = match.group(3).split()
  17. if(deprecatedTag in tags):
  18. dataWithoutDeprecated = dataWithoutDeprecated.replace(match.group(0),'')
  19. print('Removed:'+match.group(2))
  20. with open(file_path_html, 'w') as file:
  21. file.write(dataWithoutDeprecated)
  22. dataLengthEnd = len(dataWithoutDeprecated)
  23. print(f'POSTCOMPILE DONE, REMAINING SIZE {round(dataLengthEnd/dataLengthInitial*100,1)}%')