-
Notifications
You must be signed in to change notification settings - Fork 100
/
config.py
88 lines (71 loc) · 2.36 KB
/
config.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
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import json
import pathlib
from typing import Union
from utils import logger
version = "v4.5.0.03131957"
class Config:
setting = {
"FLAG_AUTO_ARCHIVE": True,
"FLAG_CHECK_UPDATE": True,
"FLAG_SHOW_REPORT": True,
"FLAG_WRITE_XLSX": True,
"FLAG_USE_CONFIG_URL": True,
"FLAG_USE_CLOUDYS_LOG_URL": True,
"FLAG_USE_LOG_URL": True,
"FLAG_USE_CLIPBOARD": True,
"FLAG_USE_CAPTURE": True,
"FLAG_USE_CAPTURE_BINARY": "CaptureApp.exe",
"FLAG_UIGF_JSON": True,
"url": "",
}
path = ""
def __init__(self, path: Union[str, bytes, pathlib.Path]):
self.path = path
try:
self.read()
except Exception:
logger.warning("配置文件不存在或出错, 重新生成")
self.save()
def read(self):
f = open(self.path, "r", encoding="utf-8")
self.setting.update(json.loads(f.read()))
f.close()
def set_key(self, key, value=None):
self.setting[key] = value
self.save()
def get_key(self, key):
try:
return self.setting[key]
except KeyError:
return None
def delKey(self, key):
try:
del self.setting[key]
except KeyError:
pass
self.save()
def save(self):
f = open(self.path, "w", encoding="utf-8")
f.write(json.dumps(self.setting, sort_keys=True, indent=4, separators=(",", ":")))
f.close()
if __name__ == "__main__":
"""更新前运行一次, 修改自身版本号"""
import time
import requests
def get_version():
"""从PC启动器api获取游戏版本号"""
j = requests.get("https://sdk-static.mihoyo.com/hk4e_cn/mdk/launcher/api/resource?key=eYd89JmJ&launcher_id=18").json()
version = j["data"]["game"]["latest"]["version"]
return "v{}.{}".format(version, time.strftime("%m%d%H%M"))
version = get_version()
print(f"{version}")
with open("version.txt", "w", encoding="utf8") as f:
f.write(version)
with open(__file__, "r", encoding="utf8") as f:
lines = []
for line in f.readlines():
if line.startswith('version = "'):
line = 'version = "{}"\n'.format(version)
lines.append(line)
with open(__file__, "w", encoding="utf8") as f:
f.writelines(lines)