Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import collections
- import json
- json_data = {}
- class Card:
- bad_ids = ['DDP', 'EXP', 'PRO-REL', 'DDQ', 'PRO-MISC', 'PRO-LPC', 'PRO-GDP', 'PRO-PRC']
- set_rename = {'FNM': 'FNM Promo'}
- type_values = {'White' : 0, 'Blue': 1, 'Black': 2, 'Red' : 3, 'Green' : 4, 'Gold' : 5, 'Artifact/Colourless' : 6, 'Land' : 7, 'Unknown' : 100}
- def __init__(self, name, set_name, set_id, is_foil, language):
- self.name = name
- self.set = Card.set_rename[set_id] if set_id in Card.set_rename else set_name
- self.set_id = set_id
- self.is_foil = is_foil
- self.language = language
- self.count = 1
- json_entry = json_data[self.name]
- self.card_type = json_entry["types"]
- try:
- self.colors = json_entry["colors"]
- except KeyError:
- self.colors = ["Unknown"]
- def get_card_type_value(self):
- if 'Artifact' in self.card_type:
- return 6
- if 'Land' in self.card_type:
- return 7
- if len(self.colors) > 1:
- return 5
- else:
- return Card.type_values[self.colors[0]]
- def __lt__(self, other):
- selfval = self.get_card_type_value()
- othval = other.get_card_type_value()
- if selfval == othval:
- return self.name < other.name
- else:
- return selfval < othval
- def __gt__(self, other):
- return other < self
- def __eq__(self, other):
- """Override the default Equals behavior"""
- if isinstance(other, self.__class__):
- return (self.name == other.name and self.set_id == other.set_id and self.is_foil == other.is_foil and self.language == other.language)
- return False
- def __hash__(self):
- return self.name.__hash__() ^ self.set_id.__hash__() ^ self.is_foil.__hash__() ^ self.language.__hash__()
- def get_quality_string(self):
- set_str = self.set if self.set_id in Card.bad_ids else self.set_id
- if self.is_foil:
- return set_str + ', Foil'
- else:
- return set_str
- if __name__ == "__main__":
- with open('AllCards.json') as data_file:
- json_data = json.load(data_file)
- full_card_list = []
- with open('puca.csv', 'r') as f:
- reader = csv.reader(f)
- full_card_list = list(reader)
- card_list = [Card(l[1], l[2], l[4], l[5], l[7]) for l in full_card_list[1:]]
- #compact the list
- counter = collections.Counter(card_list)
- card_list = list(counter.keys())
- for card in card_list:
- card.count = counter[card]
- card_list.sort()
- with open('output.txt', 'w') as f:
- curr_value = 0
- for card in card_list:
- if curr_value < card.get_card_type_value():
- curr_value = card.get_card_type_value()
- f.write('\n')
- if card.count > 1:
- name = '{0}x {1}'.format(card.count, card.name)
- else:
- name = card.name
- str_to_do = '{0} ({1})\n'.format(name, card.get_quality_string())
- print(str_to_do)
- f.write(str_to_do)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement