Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Useful for working with https://docs.google.com/spreadsheets/d/1ewBaWGhzG01X4OWZCwC7tkVimCP_DPi-1kGfvAHkn9M/copy
- #Data from https://github.com/HearthSim/hsdata/blob/master/CardDefs.xml
- import xml.etree.ElementTree as ET
- import sys
- #import operator
- '''Get cardset by # or str'''
- def CardSet(i):
- switcher = {
- 2: "Basic",
- 3: "Classic",
- 12: "Naxx",
- 13: "GvG", #goblins v. gnomes
- 14: "Blackrock",
- 15: "TGT", #"The grand tournament"
- 20: "LoE", #league of explorers
- 21: "ToG", #the old gods
- 23: "Kara", #Karazhan
- 25: "MSG", #Mean Streets of Gadgetzan
- 1001: "KFT", #Frozen Throne
- 1004: "KnC", #Kobolds and catacombs
- 1125: "Woods", #Witchwood
- 1127: "Boomsday", #Boomsday
- 1129: "Rastakhan", #Rumble
- 1130: "Shadows", #Rise of Shadows
- 1158: "Uldum", #Saviors of Uldum
- #--- end support---
- 1347: "DoD", #Descent of Dragons
- 1403: "Galakrond",
- 1414: "AoO", #Ashes of Outland
- 1443: "Scholo", #Scholomance Academy
- 1463: "Demon", #Demon Hunter Initiate
- 1466: "Madness", #Madness at the Darkmoon Faire
- 4: "HoF",
- 18: "HoF",
- 1130: "HoF",
- 1452: "HoF",
- 1453: "HoF",
- }
- #print(i)
- if(type(i) is str and i.isnumeric()):
- i = int(i)
- if(type(i) is int):
- return switcher.get(i, "INVALID")
- else:
- for key, value in switcher.items():
- if value.lower() == i.lower():
- #print(f'{key}: {value}')
- return key
- return "INVALID"
- '''Get class by # or str'''
- def HS_Class(i):
- switcher = {
- 2: "Druid",
- 3: "Hunter",
- 4: "Mage",
- 5: "Paladin",
- 6: "Priest",
- 7: "Rogue",
- 8: "Shaman",
- 9: "Warlock",
- 10: "Warrior",
- 12: "Neutral",
- 14: "Demon Hunter",
- }
- #print(i)
- if(type(i) is str and i.isnumeric()):
- i = int(i)
- if(type(i) is int):
- return switcher.get(i, "INVALID")
- else:
- for key, value in switcher.items():
- if value == i:
- #print(f'{key}: {value}')
- return key
- def HS_ClassSort(e):
- return e[4][0]
- '''Get Rarity by # or str'''
- def Rarity(i):
- switcher = {
- 1: "Common",
- 2: "NA",
- 3: "Rare",
- 4: "Epic",
- 5: "Legendary",
- }
- #print(i)
- if(type(i) is str and i.isnumeric()):
- i = int(i)
- if(type(i) is int):
- return switcher.get(i, "INVALID")
- else:
- for key, value in switcher.items():
- if value == i:
- #print(f'{key}: {value}')
- return key
- def RaritySort(e):
- return e[2][0]
- '''Prints elements'''
- def ElemPrint(elem):
- for subtags in elem:
- print(subtags.tag, subtags.attrib)
- tree = ET.parse("CardDefs.xml")
- root = tree.getroot()
- filter_on_id = CardSet(sys.argv[1]) if (len(sys.argv) > 1) else 1466
- cardsfound = list()
- dupelist = list()
- for elem in root.findall('Entity'):
- # How to make decisions based on attributes even in 2.6:
- id = int(elem.get('ID'))
- if(elem.get('CardID').find("HERO") == -1): #id > 54870 and ... filter by upper ids
- name = elem.find('Tag/enUS').text.replace(',', '')
- matches = [match for match in dupelist if name in match]
- if(len(matches) == 0):
- #ElemPrint(elem)
- rare = elem.find('.//Tag[@name="RARITY"]')
- cardset = elem.find('.//Tag[@name="CARD_SET"]')
- collectible = elem.find('.//Tag[@name="COLLECTIBLE"]')
- hs_class = elem.find('.//Tag[@name="CLASS"]')
- cardset_id = int(cardset.get('value'))
- if(rare != None and collectible != None and cardset_id == filter_on_id): # and cardset_id == 1443 ... filter by expansion
- dupelist.append(name)
- cardsfound.append([elem.get('ID'),
- name,
- [ int(rare.get('value')),
- Rarity(int(rare.get('value')))],
- CardSet(cardset_id),
- [ int(hs_class.get('value')),
- HS_Class(int(hs_class.get('value')))]]
- )
- #print(elem.get('ID') + "," + name +
- # "," + Rarity(int(rare.get('value'))) +
- # "," + CardSet(cardset_id))
- cardsfound.sort(key=RaritySort)
- cardsfound.sort(key=HS_ClassSort)
- for card in cardsfound:
- print(card[0] + "," +
- card[1] + "," +
- card[2][1] + "," +
- card[3] + "," +
- card[4][1])
Add Comment
Please, Sign In to add comment