|
@@ -0,0 +1,62 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+import os
|
|
|
+import fileinput
|
|
|
+import re
|
|
|
+import sys
|
|
|
+
|
|
|
+
|
|
|
+modTag = "mod"
|
|
|
+
|
|
|
+file_path_html = 'glife.html'
|
|
|
+file_path_mod = 'mods/mod.html'
|
|
|
+file_path_localmod = 'mods/glife_local_mod.html'
|
|
|
+file_path_remotemod = 'mods/glife_remote_mod.html'
|
|
|
+
|
|
|
+file_path_modloader = 'mods/util/ModloaderScript.txt'
|
|
|
+
|
|
|
+data = ''
|
|
|
+modData = ''
|
|
|
+scripts = ''
|
|
|
+dataWithoutModStuff = ''
|
|
|
+
|
|
|
+with open(file_path_html, 'r') as file:
|
|
|
+ data = file.read()
|
|
|
+
|
|
|
+dataWithoutModStuff = 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(modTag in tags):
|
|
|
+ modData += match.group(0)+'\n'
|
|
|
+ dataWithoutModStuff = dataWithoutModStuff.replace(match.group(0),'')
|
|
|
+
|
|
|
+ i += 1
|
|
|
+ if(i % 100 == 0):
|
|
|
+ print(i)
|
|
|
+
|
|
|
+regex = r"""/\*\s*Start Mod:\s*"Mod"\s*\*/(.*?)/\*\s*End Mod:\s*"Mod"\s*\*/"""
|
|
|
+for match in re.finditer(regex,data,re.S):
|
|
|
+ scripts += match.group(1)
|
|
|
+ dataWithoutModStuff = dataWithoutModStuff.replace(match.group(0),'')
|
|
|
+
|
|
|
+modData += '<script>'+scripts+'</script>'
|
|
|
+
|
|
|
+with open(file_path_mod, 'w') as file:
|
|
|
+ file.write(modData)
|
|
|
+
|
|
|
+
|
|
|
+data_localmod = dataWithoutModStuff.replace('</tw-storydata>',modData+'</tw-storydata>',1)
|
|
|
+with open(file_path_localmod, 'w') as file:
|
|
|
+ file.write(data_localmod)
|
|
|
+
|
|
|
+
|
|
|
+with open(file_path_modloader, 'r') as file:
|
|
|
+ modloader_data = file.read()
|
|
|
+data_remtotemod = re.sub(r"""(<script id="script-sugarcube" type="text/javascript">)(.*?)(</script>)""",r"""\1"""+modloader_data+r""" \2}\3""",dataWithoutModStuff,1, re.S)
|
|
|
+with open(file_path_remotemod, 'w') as file:
|
|
|
+ file.write(data_remtotemod)
|
|
|
+
|
|
|
+print('Done')
|