forked from sunfkny/genshin-gacha-export
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
42 lines (34 loc) · 994 Bytes
/
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
import json
import os
class Config:
setting = {}
path = ""
def __init__(self, path="config.json"):
self.path = path
try:
f = open(path, "r", encoding="utf-8")
self.setting = json.loads(f.read())
f.close()
except Exception as e:
print("配置文件出错",e)
input("请经解压后运行或重新下载")
exit()
def setKey(self, key, value=None):
self.setting[key] = value
self.save()
def getKey(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):
settingstr = json.dumps(self.setting, sort_keys=True, indent=4, separators=(",", ":"))
f = open(self.path, "w", encoding="utf-8")
f.write(settingstr)
f.close()