forked from mkzi-nya/milthm-calculator-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush.py
More file actions
61 lines (47 loc) · 1.55 KB
/
push.py
File metadata and controls
61 lines (47 loc) · 1.55 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import sys
import hashlib
def x(ouo):
if not ouo in ['y','Y','yes','Yes','YES']:
print("abort.")
exit(0)
def short(c):
return c if len(c) <= 16 else c[:15]
# 自动切换目录
orig_dir = os.getcwd()
script_dir = os.path.abspath(os.path.dirname(__file__))
os.chdir(script_dir)
# 判断是否带y参数
auto_yes = len(sys.argv) > 1 and sys.argv[1].lower() == 'y'
if not auto_yes:
ui = input("真的要继续吗?确保你的修改已应用于index.model.html,所有index.html的修改将丢失!(y/[n]):")
x(ui)
# 读取两个 JS 文件并生成哈希
with open("./js/cha_newui.js", "rb") as f:
js1_hash = short(hashlib.md5(f.read()).hexdigest()).encode()
with open("./js/constant.js", "rb") as f:
js2_hash = short(hashlib.md5(f.read()).hexdigest()).encode()
# 读取模板
with open("index.model.html", "rb") as f:
c = f.read()
# 按行替换哈希占位符
lines = c.splitlines()
new_lines = []
for line in lines:
if b"cha_newui.js" in line and b"oiiaiooiiiai" in line:
new_lines.append(line.replace(b"oiiaiooiiiai", js1_hash))
elif b"constant.js" in line and b"oiiaiooiiiai" in line:
new_lines.append(line.replace(b"oiiaiooiiiai", js2_hash))
else:
new_lines.append(line)
# 写入新文件
with open("index.html", "wb+") as f:
f.write(b"\n".join(new_lines))
# git 自动提交
cmd = "git add . && git commit -m \"meow\" && git push origin main"
if not auto_yes:
ui = input(f"要执行 {cmd} 吗?(y/[n]):")
x(ui)
os.system(cmd)
# 切回原目录
os.chdir(orig_dir)