Browse Source

change postCompile to purge `deprecated` passages

Stephan Fuchs 1 month ago
parent
commit
0d51fffdd5
3 changed files with 40 additions and 7 deletions
  1. 3 0
      sugarcube/src/head.txt
  2. 2 2
      sugarcube_compile.bat
  3. 35 5
      sugarcube_postCompile.py

+ 3 - 0
sugarcube/src/head.txt

@@ -0,0 +1,3 @@
+<meta name="rating" content="adult" />
+<meta name="author" content="Stephan Fuchs">
+<meta name="robots" content="nofollow" />

+ 2 - 2
sugarcube_compile.bat

@@ -8,9 +8,9 @@ rem Python -X utf8 outfits_convert.py
 rem Python -X utf8 npcs_convert.py
 
 if %PROCESSOR_ARCHITECTURE% == AMD64 (
-	CALL "%~dp0sugarcube\devTools\tweeGo\tweego_win64.exe" -o "%~dp0glife.html" "%~dp0sugarcube\src"
+	CALL "%~dp0sugarcube\devTools\tweeGo\tweego_win64.exe" --head "%~dp0sugarcube\src\head.txt" -o "%~dp0glife.html" "%~dp0sugarcube\src"
 ) else (
-	CALL "%~dp0sugarcube\devTools\tweeGo\tweego_win86.exe" -o "%~dp0glife.html" "%~dp0sugarcube\src"
+	CALL "%~dp0sugarcube\devTools\tweeGo\tweego_win86.exe" --head "%~dp0sugarcube\src\head.txt" -o "%~dp0glife.html" "%~dp0sugarcube\src"
 )
 
 Python -X utf8 sugarcube_postCompile.py

+ 35 - 5
sugarcube_postCompile.py

@@ -1,9 +1,39 @@
 #!/usr/bin/env python3
 
+import os
 import fileinput
+import re
+import sys
 
-for line in fileinput.input("glife.html", inplace=True, encoding="utf-8"):
-    #print('{} {}'.format(fileinput.filelineno(), line), end='')
-    print(line, end='')
-    if line.strip() == '<head>':
-        print('<meta name="rating" content="adult" />', end='')
+
+
+file_path_html = 'glife.html'
+deprecatedTag = "deprecated"
+
+data = ''
+
+
+with open(file_path_html, 'r') as file:
+    data = file.read()
+
+dataLengthInitial = len(data)
+
+dataWithoutDeprecated = data
+
+i = 0
+regex = r"""<tw-passagedata pid="(\d+)" name="([\s\w]+)" tags="(.*?)" (?:position="\d+,\d+" )?(?:size="\d+,\d+")?>(.*?)</tw-passagedata>"""
+for match in re.finditer(regex,data,re.S):
+    tags = match.group(3).split()
+
+    if(deprecatedTag in tags):
+        dataWithoutDeprecated = dataWithoutDeprecated.replace(match.group(0),'')
+        print('Removed:'+match.group(2))
+
+
+
+with open(file_path_html, 'w') as file:
+    file.write(dataWithoutDeprecated)
+
+dataLengthEnd = len(dataWithoutDeprecated)
+
+print(f'POSTCOMPILE DONE, REMAINING SIZE {round(dataLengthEnd/dataLengthInitial*100,1)}%')