-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
79 lines (63 loc) · 2.24 KB
/
script.py
File metadata and controls
79 lines (63 loc) · 2.24 KB
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
import ast
import json
from pathlib import Path
BASE_URL = "https://raw.githubusercontent.com/MxUserBot/mx-modules/main/modules"
def extract_value(node):
try:
return ast.literal_eval(node)
except Exception:
return None
def generate_index():
folder_name = BASE_URL.rstrip("/").split("/")[-1]
modules_dir = Path(folder_name)
index_data = {}
if not modules_dir.exists() or not modules_dir.is_dir():
return
for file in modules_dir.glob("*.py"):
if file.name.startswith("_"):
continue
try:
source = file.read_text("utf-8")
tree = ast.parse(source)
except (SyntaxError, UnicodeDecodeError):
continue
meta_info = None
for node in ast.walk(tree):
if isinstance(node, ast.ClassDef) and node.name == "Meta":
meta_info = {
"url": f"{BASE_URL.rstrip('/')}/{file.name}",
"author": "Unknown",
"dependencies": [],
"tags": []
}
mapping = {
"name": "name",
"description": "description",
"version": "version",
"dependencies": "dependencies",
"tags": "tags",
"author": "author"
}
for item in node.body:
if isinstance(item, ast.Assign):
for target in item.targets:
if isinstance(target, ast.Name) and target.id in mapping:
val = extract_value(item.value)
if val is not None:
meta_info[mapping[target.id]] = val
break
if meta_info:
index_data[file.stem] = meta_info
print(f"✅ | Indexed: {file.stem}")
else:
print(f"⚠️ | Skipped: {file.name}")
output_file = Path("index.json")
output_file.write_text(
json.dumps(index_data, indent=2, ensure_ascii=False),
encoding="utf-8"
)
if __name__ == "__main__":
try:
generate_index()
except Exception as e:
raise e