feat: use productdata as input and use classnames

This commit is contained in:
Niklas 2023-03-17 22:13:05 +01:00
parent d9c04c1bd4
commit 3b78849b23

View File

@ -19,19 +19,29 @@ def sqlescape(str):
})) }))
known_names = []
todo_types = ["roomitemtypes", "wallitemtypes"] todo_types = ["roomitemtypes", "wallitemtypes"]
# Load the JSON data from the file # Load the JSON data from the file
with open("../assets/gamedata/FurnitureData.json", encoding='utf-8') as f: with open("../assets/gamedata/FurnitureData.json", encoding='utf-8') as f:
data = json.load(f) data = json.load(f)
with open("catalog_items.sql", "w", encoding='utf-8') as f:
for todo_type in todo_types: for todo_type in todo_types:
for furni in data[todo_type]["furnitype"]: for furni in data[todo_type]["furnitype"]:
furni_id = furni["id"] known_names.append({"name": furni["name"], "classname": furni["classname"]})
if furni["name"]:
# get rid of any unwanted characters for sql and remove non latin-1 characters with open("../assets/gamedata/ProductData.json", encoding='utf-8') as f:
# check the collation of the table data = json.load(f)
furni_name = sqlescape(furni["name"][:55]).encode("latin-1", "ignore").decode("utf-8") for furni in data["productdata"]["product"]:
f.write(f"UPDATE catalog_items SET catalog_name = '{furni_name}' WHERE item_ids = '{furni_id}';\n") known_names.append({"name": furni["name"], "classname": furni["code"]})
#f.write(f"UPDATE items_base SET public_name = '{furni_name}' WHERE id = '{furni_id}';\n")
with open("catalog_items.sql", "w", encoding='utf-8') as f:
for furni in known_names:
# get rid of any unwanted characters for sql and remove non latin-1 characters
# check the collation of the table
if furni["name"] is None:
continue
furni_name = sqlescape(furni["name"].encode("latin-1", "ignore").decode("latin-1"))[:55]
classname = sqlescape(furni["classname"].encode("latin-1", "ignore").decode("latin-1"))
#f.write(f"UPDATE catalog_items ci SET ci.catalog_name = '{furni_name}' WHERE item_ids IN (SELECT CAST(id AS CHAR) FROM items_base WHERE item_name = '{classname}');\n")
f.write(f"UPDATE catalog_items ci, (SELECT CAST(id AS CHAR) as id, item_name FROM items_base WHERE item_name = '{classname}') item SET ci.catalog_name = '{furni_name}' WHERE ci.item_ids = item.id;\n")