-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf2_optionconfigs.py
63 lines (53 loc) · 1.83 KB
/
f2_optionconfigs.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
import json
import codecs
import os.path as osp
default_config = {
"选择同步设备":{
"OBS 录像": True,
"USV 超声": True,
"小显微镜": True,
"ArControl": True
},
"启用快捷键控制": True,
"启用socket server控制": True,
"启用倒计时": True,
"倒计时秒数": 15*60+1,
"启用微信推送": False,
"微信推送密钥": [
"<corp_id>", #corp_id
"<secret>", #secret key
"<agent_id>" #agent_id
],
"微信推送中继代理服务器":{
"http_proxy": None,
"https_proxy": None
},
"微信推送内容": "[行为间2] 结束录制",
}
filenames = [osp.join(osp.dirname(__file__), '.f2_config'), #high priority first
osp.join(osp.expanduser("~"), '.f2_config')] #low priority last
filereal = None
def load_config():
global filereal
if filereal is None:
for filename in filenames:
if osp.exists(filename):
filereal = filename
break
else:
filereal = filenames[-1]
if osp.exists(filereal):
with codecs.open(filereal, 'r', encoding='utf-8') as f:
config_tmp = json.load(f)
config = default_config.copy()
config.update(config_tmp) # update with config file values, but keep default values for keys not in config file. (This
else:
config = default_config
with codecs.open(filereal, 'w', encoding='utf-8') as f: # write defaults to file to restore on next run
json.dump(default_config, f, indent=2, ensure_ascii=False) # save defaults to file
return config
def save_config(config):
if filereal is None:
load_config()
with codecs.open(filereal, 'w', encoding='utf-8') as f:
json.dump(config, f, indent=2, ensure_ascii=False)