This repository has been archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
updateconfig.py
103 lines (81 loc) · 3.41 KB
/
updateconfig.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import json5
import sys
import os
from utils import jsonDumps
from utils import updateConfig
# 迁移推送配置
def migratePush(setting, template):
if 'push' in setting:
return
keys = [
'serverChan', 'pushPlus', 'CoolPush', 'WeCom', 'Telegram',
]
if 'CoolPush' in setting:
if 'method' in setting['CoolPush']:
setting['CoolPush']['method'] = setting['CoolPush']['method'][0]
for key in keys:
if key in setting and key in template['push']:
if 'push' not in setting:
setting['push'] = {}
setting['push'][key] = updateConfig(setting[key], template['push'][key])
del setting[key]
def migrateTask(setting, template):
if 'yunbei_task' in setting:
yunbei_task = setting['yunbei_task']
kv = {'发布动态': '162005', '访问云音乐商城': '216002',
'云贝推歌': '200002', '发布Mlog': '162006', '分享歌曲/歌单': '166000'}
for key in kv:
if key in yunbei_task and kv[key] in template['yunbei_task']:
yunbei_task[kv[key]] = updateConfig(yunbei_task[key], template['yunbei_task'][kv[key]])
del yunbei_task[key]
if 'musician_task' in setting:
musician_task = setting['musician_task']
kv = {'登录音乐人中心': '800004', '发布动态': '801005', '发布主创说': '755000', '回复粉丝评论': '732004', '回复粉丝私信': '807006',
'749006': '800004', '740004': '801005', '396002': '755000', '393001': '732004', '755001': '807006', '740005': '797005', '744005': '811003'}
for key in kv:
if key in musician_task and kv[key] in template['musician_task']:
musician_task[kv[key]] = updateConfig(musician_task[key], template['musician_task'][kv[key]])
del musician_task[key]
if 'vip_task' in setting:
vip_task = setting['vip_task']
kv = {'创建共享歌单': '816', '709004': '816'}
for key in kv:
if key in vip_task and kv[key] in template['vip_task']:
vip_task[kv[key]] = updateConfig(vip_task[key], template['vip_task'][kv[key]])
del vip_task[key]
def processSetting(setting, template):
if 'stopPushOnAPIGateway' in setting:
del setting['stopPushOnAPIGateway']
migratePush(setting, template)
migrateTask(setting, template)
def before(src, dst):
if 'sha' in src:
del src['sha']
if 'sha' in dst and dst['sha'] == 'commitId':
result = os.popen('git rev-parse HEAD').read().strip()
if len(result) == 40 and ' ' not in result:
dst['sha'] = result
else:
dst['sha'] = ''
for user in src['users']:
if 'md5' in user:
del user['md5']
if 'setting' in user:
processSetting(user['setting'], dst['setting'])
setting = src['setting']
processSetting(setting, dst['setting'])
key_list = ['version', 'desp']
for key in key_list:
if key in dst:
src[key] = dst[key]
else:
if key in src:
del src[key]
with open(sys.argv[1], 'r', encoding='utf-8') as f:
config = json5.load(f)
with open(sys.argv[2], 'r', encoding='utf-8') as f:
oldconfig = json5.load(f)
before(oldconfig, config)
data = updateConfig(oldconfig, config)
with open(sys.argv[3], 'w', encoding='utf-8') as f:
f.write(jsonDumps(data))