-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_ruffle.py
36 lines (30 loc) · 1.55 KB
/
add_ruffle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import re
try:
from commands import *
except ImportError:
print("install commands with command 'pip3 install git+https://github.com/egigoka/commands")
htmls = 0
for root, dirs, files in OS.walk('.'):
for file in files:
if file.endswith(".html"):
htmls += 1
cnt = 0
for root, dirs, files in OS.walk('.'):
for file in files:
if file.endswith(".html"):
cnt += 1
print(f"\n{cnt} of {htmls}")
path = Path.combine(root, file)
print("start", path)
contents = File.read(path, auto_detect_encoding=10000000000)
contents = contents.replace("</head>", "</head>\n<script src=\"https://unpkg.com/@ruffle-rs/ruffle\"></script>")
while "\n<script src=\"https://unpkg.com/@ruffle-rs/ruffle\"></script>\n<script src=\"https://unpkg.com/@ruffle-rs/ruffle\"></script>" in contents:
contents = contents.replace("\n<script src=\"https://unpkg.com/@ruffle-rs/ruffle\"></script>\n<script src=\"https://unpkg.com/@ruffle-rs/ruffle\"></script>", "\n<script src=\"https://unpkg.com/@ruffle-rs/ruffle\"></script>")
heads = 0
while len([m.start() for m in re.finditer('<head>', contents)]) > 1:
contents = contents[:contents.rfind("<head>")] # cut off heads
heads += 1
print(f"\tcut {heads} heads")
File.write(path, contents, mode="w")
print("done", path)
input("press Enter to exit")