def parse_rune_data(rune_data, owner): com2us_id = rune_data.get('rune_id') rune = RuneInstance.objects.filter(com2us_id=com2us_id, owner=owner).first() if not rune: rune = RuneInstance() # Basic rune info rune.type = rune_set_map.get(rune_data.get('set_id')) rune.com2us_id = com2us_id rune.value = rune_data.get('sell_value') rune.slot = rune_data.get('slot_no') rune.stars = rune_data.get('class') rune.level = rune_data.get('upgrade_curr') original_quality = rune_data.get('extra') if original_quality: rune.original_quality = rune_quality_map[original_quality] # Rune stats main_stat = rune_data.get('pri_eff') if main_stat: rune.main_stat = rune_stat_type_map.get(main_stat[0]) rune.main_stat_value = main_stat[1] innate_stat = rune_data.get('prefix_eff') if innate_stat: rune.innate_stat = rune_stat_type_map.get(innate_stat[0]) rune.innate_stat_value = innate_stat[1] substats = rune_data.get('sec_eff', []) if len(substats) >= 1: rune.substat_1 = rune_stat_type_map.get(substats[0][0]) rune.substat_1_value = substats[0][1] + substats[0][3] if substats[0][3]: rune.substat_1_craft = RuneInstance.CRAFT_GRINDSTONE elif substats[0][2]: rune.substat_1_craft = RuneInstance.CRAFT_ENCHANT_GEM if len(substats) >= 2: rune.substat_2 = rune_stat_type_map.get(substats[1][0]) rune.substat_2_value = substats[1][1] + substats[1][3] if substats[1][3]: rune.substat_2_craft = RuneInstance.CRAFT_GRINDSTONE elif substats[1][2]: rune.substat_2_craft = RuneInstance.CRAFT_ENCHANT_GEM if len(substats) >= 3: rune.substat_3 = rune_stat_type_map.get(substats[2][0]) rune.substat_3_value = substats[2][1] + substats[2][3] if substats[2][3]: rune.substat_3_craft = RuneInstance.CRAFT_GRINDSTONE elif substats[2][2]: rune.substat_3_craft = RuneInstance.CRAFT_ENCHANT_GEM if len(substats) >= 4: rune.substat_4 = rune_stat_type_map.get(substats[3][0]) rune.substat_4_value = substats[3][1] + substats[3][3] if substats[3][3]: rune.substat_4_craft = RuneInstance.CRAFT_GRINDSTONE elif substats[3][2]: rune.substat_4_craft = RuneInstance.CRAFT_ENCHANT_GEM return rune
def parse_rune_data(rune_data, owner): com2us_id = rune_data.get('rune_id') rune = RuneInstance.objects.filter(com2us_id=com2us_id, owner=owner).first() if not rune: rune = RuneInstance() # Make sure it's saved as a new instance and marked as an import rune.pk = None rune.uncommitted = True # Basic rune info rune.type = rune_set_map.get(rune_data.get('set_id')) rune.com2us_id = com2us_id rune.value = rune_data.get('sell_value') rune.slot = rune_data.get('slot_no') rune.stars = rune_data.get('class') rune.level = rune_data.get('upgrade_curr') # Rune stats main_stat = rune_data.get('pri_eff') if main_stat: rune.main_stat = rune_stat_type_map.get(main_stat[0]) rune.main_stat_value = main_stat[1] innate_stat = rune_data.get('prefix_eff') if innate_stat: rune.innate_stat = rune_stat_type_map.get(innate_stat[0]) rune.innate_stat_value = innate_stat[1] substats = rune_data.get('sec_eff', []) if len(substats) >= 1: rune.substat_1 = rune_stat_type_map.get(substats[0][0]) rune.substat_1_value = substats[0][1] + substats[0][3] if substats[0][3]: rune.substat_1_craft = RuneInstance.CRAFT_GRINDSTONE elif substats[0][2]: rune.substat_1_craft = RuneInstance.CRAFT_ENCHANT_GEM if len(substats) >= 2: rune.substat_2 = rune_stat_type_map.get(substats[1][0]) rune.substat_2_value = substats[1][1] + substats[1][3] if substats[1][3]: rune.substat_2_craft = RuneInstance.CRAFT_GRINDSTONE elif substats[1][2]: rune.substat_2_craft = RuneInstance.CRAFT_ENCHANT_GEM if len(substats) >= 3: rune.substat_3 = rune_stat_type_map.get(substats[2][0]) rune.substat_3_value = substats[2][1] + substats[2][3] if substats[2][3]: rune.substat_3_craft = RuneInstance.CRAFT_GRINDSTONE elif substats[2][2]: rune.substat_3_craft = RuneInstance.CRAFT_ENCHANT_GEM if len(substats) >= 4: rune.substat_4 = rune_stat_type_map.get(substats[3][0]) rune.substat_4_value = substats[3][1] + substats[3][3] if substats[3][3]: rune.substat_4_craft = RuneInstance.CRAFT_GRINDSTONE elif substats[3][2]: rune.substat_4_craft = RuneInstance.CRAFT_ENCHANT_GEM return rune