-
Notifications
You must be signed in to change notification settings - Fork 5
/
modify_json.py
32 lines (25 loc) · 899 Bytes
/
modify_json.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
import os
import json
def modify_links(json_content):
for item in json_content:
for key, value in item.items():
if isinstance(value, str) and 'http' in value:
if key != 'RepoUrl':
item[key] = f"https://gh.atmoomen.top/{value}"
return json_content
def main():
pluginmaster_path = 'pluginmaster.json'
pluginmaster_cn_path = 'pluginmaster-cn.json'
if not os.path.exists(pluginmaster_path):
print(f"{pluginmaster_path} does not exist.")
return
with open(pluginmaster_path, 'r') as f:
pluginmaster = json.load(f)
if pluginmaster == []:
print("pluginmaster.json is empty.")
return
modified_pluginmaster = modify_links(pluginmaster)
with open(pluginmaster_cn_path, 'w') as f:
json.dump(modified_pluginmaster, f, indent=4)
if __name__ == "__main__":
main()