Files
aostats-custom/scripts/item_category_map.py
T
2020-01-20 21:47:41 +01:00

33 lines
818 B
Python

# Helper script used to generate frontend/src/assets/item_category_map.json
# Args: items.xml generated by ao-id-extractor
# Usage python scripts/item_category_map.py items.xml > frontend/src/assets/item_category_map.json
import json
import re
import sys
import xml.etree.ElementTree as ET
file = sys.argv[1]
def add_item(db, name, item):
if 'craftingcategory' in item:
db[name] = item['craftingcategory']
nd = {}
tree = ET.parse(file)
root = tree.getroot()
for child in root:
if not 'uniquename' in child.attrib:
continue
add_item(nd, child.attrib['uniquename'], child.attrib)
ench = child.find("enchantments")
if ench:
for e in ench:
add_item(nd, f"{child.attrib['uniquename']}@{e.attrib['enchantmentlevel']}", child.attrib)
print(json.dumps(nd))