-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistmods.py
50 lines (42 loc) · 1.29 KB
/
listmods.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
import json
import os
addons_path = "./"
directory_contents = os.listdir(addons_path)
mods = []
for dir in directory_contents:
if os.path.isdir(dir):
files = os.listdir(addons_path+dir)
for file in files:
file_path= addons_path+dir+"/"+file
if file.__contains__("ServerData.json") and os.stat(file_path).st_size != 0:
#print(dir, file_path,os.path.getsize(file_path))
#utf-8 with BOM encoding
with open(file_path, 'r+', encoding="utf_8_sig") as f:
data = json.loads(f.read())
mod ={
"modId": data['id'],
"name": data['name'],
"version": data["revision"]['version']
}
mods.append(mod)
if len(mods)>1:
with open('mods.json', 'w') as f:
json.dump(mods, f)
print("The json file is created")
#example: Input
# {
# "id": "5614E4816F653D1A",
# "name": "Sample Mod - Workbench Plugin",
# "revision": {
# "version": "1.0.1",
# "dependencies": [],
# "scenarios": [],
# "downloaded": true
# }
# }
#example: Output
# {
# "modId": "596B3717B10FFB07",
# "name": "MapAndDrive",
# "version": "1.0.1"
# }