-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-modlist
executable file
·66 lines (51 loc) · 1.87 KB
/
gen-modlist
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
#!/usr/bin/env python
#import os
import glob
from tomlkit import parse
MODLIST_FN = "modlist.md"
IGNORE_FILES = ["pack.toml", "index.toml"]
def find_toml_files():
toml_files = glob.glob('**/*.toml', recursive=True)
toml_files = [f for f in toml_files if f not in IGNORE_FILES]
return toml_files
def parse_toml_file(filepath):
with open(filepath, 'r') as file:
data = parse(file.read())
return data
def generate_modlist():
toml_files = find_toml_files()
mods = []
archived = []
for filepath in toml_files:
data = parse_toml_file(filepath)
mod_name = data.get('name', 'Unknown Mod')
project_url = data.get('metadata', {}).get('curseforge',
{}).get('website', '')
if filepath.startswith('archive/'):
archived.append((mod_name, project_url))
continue
categories = data.get('metadata', {}).get('curseforge',
{}).get('categories', [])
mod_class = project_url.split('/')[-2] if project_url else 'Unknown Class'
for category in categories:
mods.append((mod_class, category, mod_name, project_url))
mods.sort(key=lambda x: (x[0], x[1], x[2]))
with open(MODLIST_FN, "w") as file:
file.write("# ModList for HarleyColonies\n\n")
current_class = None
current_category = None
for mod_class, category, mod_name, project_url in mods:
if mod_class != current_class:
if current_class is not None:
file.write("\n")
file.write(f"## {mod_class}\n\n")
current_class = mod_class
current_category = None
if category != current_category:
if current_category is not None:
file.write("\n")
file.write(f"### {category}\n\n")
current_category = category
file.write(f"- [{mod_name}]({project_url})\n")
if __name__ == "__main__":
generate_modlist()