-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_modes.py
More file actions
48 lines (37 loc) · 1.26 KB
/
Copy pathprocess_modes.py
File metadata and controls
48 lines (37 loc) · 1.26 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
import os
import json
MODES_DIR = 'modes'
OUTPUT_FILE = 'modes.json'
def process_modes():
modes = []
if not os.path.exists(MODES_DIR):
print(f"Directory '{MODES_DIR}' not found. Creating it...")
os.makedirs(MODES_DIR)
return []
print(f"Scanning '{MODES_DIR}' for images...")
for filename in os.listdir(MODES_DIR):
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.webp', '.gif')):
name_no_ext = os.path.splitext(filename)[0]
title = name_no_ext.replace('_', ' ')
modes.append({
"id": name_no_ext,
"name": title,
"url": f"{MODES_DIR}/{filename}",
"type": "gamemode"
})
modes.sort(key=lambda x: x['name'])
return modes
def save_json(data, output_file):
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
print(f"Saved {len(data)} modes to {output_file}")
def main():
try:
modes_data = process_modes()
save_json(modes_data, OUTPUT_FILE)
print("\nProcessing complete!")
except Exception as e:
print(f"Error: {e}")
raise
if __name__ == '__main__':
main()