import os import re def parse_ci(infile): itemName = infile.split("/")[1].split(".")[0] print("-------------------------------") print(infile) print("-------------------------------") id_reverse_map = { "Neutral Damage": "nDam", "Fire Damage": "fDam", "Water Damage": "wDam", "Air Damage": "aDam", "Thunder Damage": "tDam", "Earth Damage": "eDam", "ealth": "hp", # HACKY "Fire Defense": "fDef", "Water Defense": "wDef", "Air Defense": "aDef", "Thunder Defense": "tDef", "Earth Defense": "eDef", "Combat Lv. Min": "lvl", "Strength Min": "strReq", "Dexterity Min": "dexReq", "Intelligence Min": "intReq", "Defense Min": "defReq", "Agility Min": "agiReq", "% Health Regen": "hprPct", "/4s Mana Regen": "mr", "% Spell Damage": "sdPct", "% Main Attack Damage": "mdPct", "/4s Life Steal": "ls", "/4s Mana Steal": "ms", "% XP Bonus": "xpb", "% Loot Bonus": "lb", "% Reflection": "ref", "Strength": "str", "Dexterity": "dex", "Intelligence": "int", "Agility": "agi", "Defense": "def", "% Thorns": "thorns", "% Exploding": "expd", "% Walk Speed": "spd", "tier Attack Speed": "atkTier", "/3s Poison": "poison", "Health": "hpBonus", "% Soul Point Regen": "spRegen", "% Stealing": "eSteal", "Health Regen": "hprRaw", "Spell Damage": "sdRaw", "Main Attack Damage": "mdRaw", "% Fire Damage": "fDamPct", "% Water Damage": "wDamPct", "% Air Damage": "aDamPct", "% Thunder Damage": "tDamPct", "% Earth Damage": "eDamPct", "% Fire Defense": "fDefPct", "% Water Defense": "wDefPct", "% Air Defense": "aDefPct", "% Thunder Defense": "tDefPct", "% Earth Defense": "eDefPct", "% 1st Spell Cost": "spPct1", "1st Spell Cost": "spRaw1", "% 2nd Spell Cost": "spPct2", "2nd Spell Cost": "spRaw2", "% 3rd Spell Cost": "spPct3", "3rd Spell Cost": "spRaw3", "% 4th Spell Cost": "spPct4", "4th Spell Cost": "spRaw4", "rainbowSpellDamageRaw": "rainbowRaw", "% Sprint": "sprint", "% Sprint Regen": "sprintReg", "Jump Height": "jh", "lootQuality": "lq", "gatherXpBonus": "gXp", "gatherSpeed": "gSpd", } weapons = [ "bow", "wand", "spear", "dagger", "relik" ] armors = [ "helmet", "chestplate", "leggings", "boots" ] accessories = [ "ring", "bracelet", "necklace" ] item_dict = dict() with open(infile, "r") as _infile: item_data = _infile.read() item_data = item_data.split("
")[0].split("/items/v4//",1)[1] type_info = item_data.split("/", 1)[0] item_data = item_data.split("p class='name ",1)[1] tier_info = item_data.split("'",1)[0] item_dict["tier"] = tier_info item_dict["type"] = type_info item_dict["name"] = itemName + " (1.20)" item_dict["displayName"] = item_dict["name"] item_dict["set"] = None item_dict["quest"] = None item_dict["classReq"] = None # Ignoring cause I'm not checking anyway item_dict["restrict"] = "1.20 item" static_info, id_info = item_data.split("table class='") fix_id = id_info[:3] == 'td2' item_dict["fixID"] = fix_id id_info = id_info.split("/thead",1)[-1] def process_reqs(req_info): req_info = [x.split("<",1)[0] for x in req_info.split('mark">')[1:]] for req in req_info: key, val = req.split(":") item_dict[id_reverse_map[key]] = int(val) item_dict["strReq"] = 0; item_dict["dexReq"] = 0; item_dict["intReq"] = 0; item_dict["defReq"] = 0; item_dict["agiReq"] = 0; if type_info in weapons: attack_speed, static_info = static_info.split(" Speed",1) attack_speed = attack_speed.split("attackSpeed'>",1)[1].split("Attack")[0].strip().replace(" ","_").upper() item_dict["atkSpd"] = attack_speed item_dict["category"] = "weapon" stat_info, req_info = static_info.split("Class Req: ") process_reqs(req_info) item_dict["nDam"] = "0-0"; item_dict["eDam"] = "0-0"; item_dict["tDam"] = "0-0"; item_dict["wDam"] = "0-0"; item_dict["fDam"] = "0-0"; item_dict["aDam"] = "0-0"; else: # Armor and accessory both do health and eledef if type_info in accessories: item_dict["category"] = "accessory" else: item_dict["category"] = "armor" stat_info, req_info = static_info.split('requirements') process_reqs(req_info) stat_info = stat_info.split("i class='")[1:] for stat in stat_info: key, stat = stat.split(">",1)[1][2:].replace("","",1).split("<",1)[0].split(": ") try: item_dict[id_reverse_map[key]] = int(stat) except: item_dict[id_reverse_map[key]] = stat if type_info not in accessories: id_info, slot_info = id_info.split("'bottom'>") if 'sockets' in slot_info: item_dict["slots"] = int(slot_info.split("/",1)[1].split("]",1)[0]) else: item_dict["slots"] = 0 number_regex = re.compile(r"(-?\d+)(.*)") id_info = id_info.split("