Skip to content

Instantly share code, notes, and snippets.

@Bamux
Last active February 3, 2018 14:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bamux/b4a6ca7b15c0bbc7f953a5fb3469a1e1 to your computer and use it in GitHub Desktop.
Save Bamux/b4a6ca7b15c0bbc7f953a5fb3469a1e1 to your computer and use it in GitHub Desktop.
Rift Items.xml parser
# -*- coding: utf-8 -*-
# This python Script genereats a CSV File from the Items.xml (for the selected class) which you can import in a Spredsheet
import codecs
import os
#######################################################################################################################
# Instructions
# 1. Download the latest Rift_Discoveries_xxxx-xx-xx.zip from http://webcdn.triongames.com/addons/assets/
# 2. unzip the Rift_Discovery file, you need the Items.xml from this folder
# 3. Edit the next variables:
print_header = True # if you want to print a header ItemKey, Itemname, Slot ... for the CSV file (True or False)
discovery_date = "2018-01-24" # Date (yyyy-mm-tt) from which you want to parse the items
selected_class = "Mage" # select Mage, Cleric, Rogue, Warrior or Primalist
selected_slot = "" # if you want to search for a specific slot (search_slot = "xyz")
selected_rarity = "" # if you want to search for a specific rarity (search_rarity = "xyz")
search_item = "" # if you want to search for a specific item (search_item = "xyz")
mainstat = 800 # only items > mainstat
# 4. save this script and copy the Item.xml and this script in the same Folder
#######################################################################################################################
def csv():
global ExistingItemKey
existing = False
for item_key in ExistingItemKey:
if item_key == ItemKey:
existing = True
if not existing:
ExistingItemKey += [ItemKey]
if search_item or selected_slot or selected_rarity:
if search_item:
if search_item in English or search_item in German or search_item in French:
create_csv()
else:
if selected_slot and selected_rarity:
if selected_slot == Slot and selected_rarity == Rarity:
create_csv()
elif selected_slot:
if selected_slot == Slot:
create_csv()
elif selected_rarity:
if selected_rarity == Rarity:
create_csv()
else:
create_csv()
def create_csv():
if selected_class == "Mage" or selected_class == "Cleric":
line = ItemKey + "\t" + English + "\t" + German + "\t" + French + "\t" + Rarity + "\t" + Slot + "\t" + ArmorType\
+ "\t" + Armor + "\t" + Intelligence + "\t" + Wisdom + "\t" + Endurance + "\t" + SpellPower\
+ "\t" + SpellCriticalHit + "\t" + CritPowerRating + "\t" + Dodge + "\t" + ShieldBlock + "\t" + Guard\
+ "\t" + Resistance + "\t" + HitBonus + "\t" + Description_English + "\t" + first_discovery + "\n"
line = line.replace("'", "'")
file_out.write(line)
print(ItemKey, "\t", English, "\t", German, "\t", French, "\t", Rarity, "\t", Slot, "\t", ArmorType, "\t",
Armor, "\t", Intelligence, "\t", Wisdom, "\t", Endurance, "\t", SpellPower, "\t",
SpellCriticalHit, "\t", CritPowerRating, "\t", Dodge, "\t", ShieldBlock, "\t", Guard,
"\t", Resistance, "\t", HitBonus, "\t", Description_English, "\t", first_discovery)
else:
line = ItemKey + "\t" + English + "\t" + German + "\t" + French + "\t" + Rarity + "\t" + Slot + "\t" + ArmorType\
+ "\t" + Armor + "\t" + Strength + "\t" + Dexterity + "\t" + Endurance + "\t" + SpellPower\
+ "\t" + SpellCriticalHit + "\t" + CritPowerRating + "\t" + Dodge + "\t" + ShieldBlock + "\t" + Guard\
+ "\t" + Resistance + "\t" + HitBonus + "\t" + Description_English + "\t" + first_discovery + "\n"
line = line.replace("'", "'")
file_out.write(line)
print(ItemKey, "\t", English, "\t", German, "\t", French, "\t", Rarity, "\t", Slot, "\t", ArmorType, "\t",
Armor, "\t", Strength, "\t", Dexterity, "\t", Endurance, "\t", SpellPower, "\t",
SpellCriticalHit, "\t", CritPowerRating, "\t", Dodge, "\t", ShieldBlock, "\t", Guard,
"\t", Resistance, "\t", HitBonus, "\t", Description_English, "\t", first_discovery)
Item = False
Name = False
ItemKey = ""
English = ""
German = ""
French = ""
Rarity = ""
RuneAllowedSlots = ""
Slot = ""
ArmorType = ""
Armor = ""
OnUse = False
Ability = False
OnUse_English = ""
Ability_English = ""
OnEquip = False
ItemSet = False
HitBonus = ""
Strength = ""
Dexterity = ""
Intelligence = ""
Wisdom = ""
Endurance = ""
SpellPower = ""
AttackPower = ""
SpellCriticalHit = ""
CriticalHit = ""
CritPowerRating = ""
Dodge = ""
ShieldBlock = ""
Guard = ""
Resistance = ""
Description = ""
Description_English = ""
Description_Item = ""
ItemSet_English = ""
RequiredLevel = ""
Calling = ""
Date = ""
first_discovery = ""
last_date = ""
copy = ""
ExistingItemKey = []
if not search_item:
if os.path.isfile("ExistingItemKey.txt"):
file = codecs.open("ExistingItemKey.txt", 'r', "utf-8")
for key in file:
key = key.strip()
if key:
ExistingItemKey += [key]
file.close()
if os.path.isfile(selected_class + ".csv"):
os.remove(selected_class + ".csv")
file_out = codecs.open(selected_class + ".csv", "w", 'utf-8')
if print_header:
if selected_class == "Mage" or selected_class == "Cleric":
header = "ItemKey\tEnglish\tGerman\tFrench\tRarity\tSlot\tArmorType\tArmor\tIntelligence\tWisdom\tEndurance\t" \
"SpellPower\tSpellCriticalHit\tCritPowerRating\tDodge\tShieldBlock\tGuard\tResitence\tHitBonus\t" \
"Description\tFirst Discovery\n"
else:
header = "ItemKey\tEnglish\tGerman\tFrench\tRarity\tSlot\tArmorType\tArmor\tStr\tDex\tEndurance\tAP\tCrit\tCP\t" \
"Dodge\tShieldBlock\tGuard\tResitence\tHitBonus\tDescription\tFirst Discovery\n"
file_out.write(header)
print(header)
file = codecs.open("Items.xml", 'r', "utf-8")
for item in file:
if "<Item>" in item:
Item = True
elif "</Item>" in item:
if first_discovery:
if selected_class == "Mage":
if Intelligence:
if int(Intelligence) > mainstat:
if Wisdom:
if int(Intelligence) >= int(Wisdom):
csv()
else:
csv()
elif selected_class == "Cleric":
if Intelligence or Wisdom or SpellPower or SpellCriticalHit or CritPowerRating and not Strength and not Dexterity:
if Intelligence and Wisdom:
if int(Wisdom) > mainstat and int(Wisdom) >= int(Intelligence):
csv()
elif selected_class == "Warrior":
if Strength and Dexterity:
if int(Strength) > mainstat and int(Strength) >= int(Dexterity):
csv()
elif selected_class == "Rogue" or selected_class == "Primalist":
if Strength and Dexterity:
if int(Dexterity) > mainstat and int(Strength) <= int(Dexterity):
csv()
Item = False
Name = False
ItemKey = ""
English = ""
German = ""
French = ""
Russian = ""
Rarity = ""
RuneAllowedSlots = ""
Slot = ""
ArmorType = ""
Armor = ""
OnUse = False
Ability = False
OnUse_English = ""
Ability_English = ""
OnEquip = False
OnEquip_English = ""
ItemSet = False
HitBonus = ""
Strength = ""
Dexterity = ""
Intelligence = ""
Wisdom = ""
SpellPower = ""
AttackPower = ""
SpellCriticalHit = ""
CriticalHit = ""
CritPowerRating = ""
Dodge = ""
ShieldBlock = ""
Guard = ""
Resistance = ""
Endurance = ""
Description = ""
Description_English = ""
Description_Item = ""
ItemSet_English = ""
RequiredLevel = ""
Calling = ""
Date = ""
if last_date:
if last_date < first_discovery:
last_date = first_discovery
else:
last_date = first_discovery
first_discovery = ""
if Item:
if "<ItemKey>" in item:
item = item.split("<ItemKey>")[1]
ItemKey = item.split("</ItemKey>")[0]
ItemKey = ItemKey.lstrip()
ItemKey = ItemKey.rstrip()
elif "<Name>" in item:
Name = True
elif "</Name>" in item:
Name = False
elif Name and "<English>" in item:
item = item.split("<English>")[1]
English = item.split("</English>")[0]
English = English.lstrip()
English = English.rstrip()
elif Name and "<German>" in item:
item = item.split("<German>")[1]
German = item.split("</German>")[0]
German = German.lstrip()
German = German.rstrip()
elif Name and "<French>" in item:
item = item.split("<French>")[1]
French = item.split("</French>")[0]
French = French.lstrip()
French = French.rstrip()
if "<Rarity>" in item:
item = item.split("<Rarity>")[1]
Rarity = item.split("</Rarity>")[0]
Rarity = Rarity.lstrip()
Rarity = Rarity.rstrip()
elif "<RuneAllowedSlots>" in item:
RuneAllowedSlots = True
elif "</RuneAllowedSlots>" in item:
RuneAllowedSlots = False
elif "<Slot>" in item:
item = item.split("<Slot>")[1]
Slot = item.split("</Slot>")[0]
Slot = Slot.lstrip()
Slot = Slot.rstrip()
if RuneAllowedSlots:
Slot = "Rune " + Slot
elif "<RiftGem>" in item:
item = item.split("<RiftGem>")[1]
Slot = item.split("</RiftGem>")[0]
Slot = Slot.lstrip()
Slot = Slot.rstrip()
elif "<ArmorType>" in item:
item = item.split("<ArmorType>")[1]
ArmorType = item.split("</ArmorType>")[0]
ArmorType = ArmorType.lstrip()
ArmorType = ArmorType.rstrip()
elif "<Armor>" in item:
item = item.split("<Armor>")[1]
Armor = item.split("</Armor>")[0]
Armor = Armor.lstrip()
Armor = Armor.rstrip()
elif "<OnUse>" in item:
OnUse = True
elif "</OnUse>" in item:
OnUse = False
elif "<Ability>" in item:
Ability = True
elif "</Ability>" in item:
Ability = False
elif OnUse and "<English>" in item:
item = item.split("<English>")[1]
OnUse_English = item.split("</English>")[0]
OnUse_English = OnUse_English.lstrip()
OnUse_English = OnUse_English.rstrip()
if Description_English:
Description_English += " | Use: " + OnUse_English
else:
Description_English = "Use: " + OnUse_English
elif Ability and "<English>" in item:
item = item.split("<English>")[1]
Ability_English = item.split("</English>")[0]
Ability_English = Ability_English.lstrip()
Ability_English = Ability_English.rstrip()
if Description_English:
Description_English += " | Equip: " + Ability_English
else:
Description_English = " Equip: " + Ability_English
elif "<SpellDamage>" in item:
item = item.split("<SpellDamage>")[1]
SpellPower = item.split("</SpellDamage>")[0]
SpellPower = SpellPower.lstrip()
SpellPower = SpellPower.rstrip()
elif "<OnEquip>" in item:
OnEquip = True
elif "</OnEquip>" in item:
OnEquip = False
if OnEquip or OnUse or Ability:
if "<English>" in item:
item = item.split("<English>")[1]
OnEquip_English = item.split("</English>")[0]
OnEquip_English = OnEquip_English.lstrip()
OnEquip_English = English.rstrip()
if Description_English:
Description_English += " | " + OnEquip_English
else:
Description_English = OnEquip_English
elif "<HitBonus>" in item:
item = item.split("<HitBonus>")[1]
HitBonus = item.split("</HitBonus>")[0]
HitBonus = HitBonus.lstrip()
HitBonus = HitBonus.rstrip()
elif "<Strength>" in item:
item = item.split("<Strength>")[1]
Strength = item.split("</Strength>")[0]
Strength = Strength.lstrip()
Strength = Strength.rstrip()
elif "<Dexterity>" in item:
item = item.split("<Dexterity>")[1]
Dexterity = item.split("</Dexterity>")[0]
Dexterity = Dexterity.lstrip()
Dexterity = Dexterity.rstrip()
elif "<Intelligence>" in item:
item = item.split("<Intelligence>")[1]
Intelligence = item.split("</Intelligence>")[0]
Intelligence = Intelligence.lstrip()
Intelligence = Intelligence.rstrip()
elif "<Wisdom>" in item:
item = item.split("<Wisdom>")[1]
Wisdom = item.split("</Wisdom>")[0]
Wisdom = Wisdom.lstrip()
Wisdom = Wisdom.rstrip()
elif "<Endurance>" in item:
item = item.split("<Endurance>")[1]
Endurance = item.split("</Endurance>")[0]
Endurance = Endurance.lstrip()
Endurance = Endurance.rstrip()
elif "<SpellPower>" in item:
item = item.split("<SpellPower>")[1]
SpellPower = item.split("</SpellPower>")[0]
SpellPower = SpellPower.lstrip()
SpellPower = SpellPower.rstrip()
elif "<AttackPower>" in item:
item = item.split("<AttackPower>")[1]
AttackPower = item.split("</AttackPower>")[0]
AttackPower = AttackPower.lstrip()
AttackPower = AttackPower.rstrip()
elif "<SpellCriticalHit>" in item:
item = item.split("<SpellCriticalHit>")[1]
SpellCriticalHit = item.split("</SpellCriticalHit>")[0]
SpellCriticalHit = SpellCriticalHit.lstrip()
SpellCriticalHit = SpellCriticalHit.rstrip()
elif "<CriticalHit>" in item:
item = item.split("<CriticalHit>")[1]
CriticalHit = item.split("</CriticalHit>")[0]
CriticalHit = CriticalHit.lstrip()
CriticalHit = CriticalHit.rstrip()
elif "<CritPowerRating>" in item:
item = item.split("<CritPowerRating>")[1]
CritPowerRating = item.split("</CritPowerRating>")[0]
CritPowerRating = CritPowerRating.lstrip()
CritPowerRating = CritPowerRating.rstrip()
elif "<Guard>" in item:
item = item.split("<Guard>")[1]
Guard = item.split("</Guard>")[0]
Guard = Guard.lstrip()
Guard = Guard.rstrip()
elif "<ShieldBlock>" in item:
item = item.split("<ShieldBlock>")[1]
ShieldBlock = item.split("</ShieldBlock>")[0]
ShieldBlock = ShieldBlock.lstrip()
ShieldBlock = ShieldBlock.rstrip()
elif "<Dodge>" in item:
item = item.split("<Dodge>")[1]
Dodge = item.split("</Dodge>")[0]
Dodge = Dodge.lstrip()
Dodge = Dodge.rstrip()
elif "<Resistance" in item:
item = item.split(">")[1]
Resistance = item.split("</")[0]
Resistance = Resistance.lstrip()
Resistance = Resistance.rstrip()
if "<ItemSet>" in item:
ItemSet = True
elif "</ItemSet>" in item:
ItemSet = False
elif ItemSet and "<English>" in item:
item = item.split("<English>")[1]
ItemSet_English = item.split("</English>")[0]
ItemSet_English = ItemSet_English.lstrip()
ItemSet_English = ItemSet_English.rstrip()
if Description_English:
if ItemSet_English not in Description_English:
Description_English += " | Set: " + ItemSet_English
else:
Description_English = "Set: " + ItemSet_English
elif "<Description>" in item:
Description = True
elif "</Description>" in item:
Description = False
elif Description and "<English>" in item:
item = item.split("<English>")[1]
Description_Item = item.split("</English>")[0]
Description_Item = Description_English.lstrip()
Description_Item = Description_English.rstrip()
if Description_English:
Description_English += " | " + Description_Item
else:
Description_English = Description_Item
elif "<RequiredLevel>" in item:
item = item.split("<RequiredLevel>")[1]
RequiredLevel = item.split("</RequiredLevel>")[0]
RequiredLevel = RequiredLevel.lstrip()
RequiredLevel = RequiredLevel.rstrip()
elif "<Date>" in item:
item = item.split("<Date>")[1]
Date = item.split("</Date>")[0]
Date = Date.lstrip()
Date = Date.rstrip()
Date = Date.split("T")[0]
if Date >= discovery_date:
if first_discovery:
if Date < first_discovery:
first_discovery = Date
else:
first_discovery = Date
file.close()
file_out.close()
if last_date:
myfile = selected_class + "(" + discovery_date + ")-(" + last_date + ").csv"
if os.path.isfile(myfile):
os.remove(myfile)
os.rename(selected_class + ".csv", myfile)
if not search_item:
file = codecs.open("ExistingItemKey.txt", 'w', "utf-8")
for key in ExistingItemKey:
file.write(key + '\r\n')
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment