-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_items.py
More file actions
72 lines (56 loc) · 1.98 KB
/
Copy pathprocess_items.py
File metadata and controls
72 lines (56 loc) · 1.98 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
import json
import urllib.request
import os
from common import get_latest_version
# URLs
ITEM_DATA_URL_TEMPLATE = "https://ddragon.leagueoflegends.com/cdn/{version}/data/en_US/item.json"
# Local files
MAPS_FILE = 'maps.json'
OUTPUT_FILE = 'items.json'
def download_items(version):
url = ITEM_DATA_URL_TEMPLATE.format(version=version)
print(f"Downloading items from {url}...")
with urllib.request.urlopen(url) as response:
return json.loads(response.read().decode('utf-8'))
def load_maps():
print(f"Loading maps from {MAPS_FILE}...")
if not os.path.exists(MAPS_FILE):
print(f"Warning: {MAPS_FILE} not found. Using default map IDs.")
return {}
with open(MAPS_FILE, 'r', encoding='utf-8') as f:
return json.load(f)
def process_items(items_data, maps_data):
print("Processing items...")
items_by_map = {}
for map_id in maps_data.keys():
if map_id == "special":
continue
items_by_map[map_id] = []
all_items = items_data['data']
for item_id, item in all_items.items():
if "placeholder" in item['name'].lower():
continue
item_maps = item.get('maps', {})
for map_id, available in item_maps.items():
if available:
if map_id not in items_by_map:
items_by_map[map_id] = []
items_by_map[map_id].append(item_id)
return items_by_map
def save_items_json(data):
print(f"Saving to {OUTPUT_FILE}...")
with open(OUTPUT_FILE, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2)
print("Done.")
def main():
try:
version = get_latest_version()
items_data = download_items(version)
maps_data = load_maps()
processed_data = process_items(items_data, maps_data)
save_items_json(processed_data)
except Exception as e:
print(f"Error: {e}")
exit(1)
if __name__ == "__main__":
main()