Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. import csv
  2. import collections
  3. import json
  4.  
  5. json_data = {}
  6.  
  7. class Card:
  8.  
  9. bad_ids = ['DDP', 'EXP', 'PRO-REL', 'DDQ', 'PRO-MISC', 'PRO-LPC', 'PRO-GDP', 'PRO-PRC']
  10. set_rename = {'FNM': 'FNM Promo'}
  11. type_values = {'White' : 0, 'Blue': 1, 'Black': 2, 'Red' : 3, 'Green' : 4, 'Gold' : 5, 'Artifact/Colourless' : 6, 'Land' : 7, 'Unknown' : 100}
  12.  
  13. def __init__(self, name, set_name, set_id, is_foil, language):
  14. self.name = name
  15. self.set = Card.set_rename[set_id] if set_id in Card.set_rename else set_name
  16. self.set_id = set_id
  17. self.is_foil = is_foil
  18. self.language = language
  19. self.count = 1
  20. json_entry = json_data[self.name]
  21. self.card_type = json_entry["types"]
  22. try:
  23. self.colors = json_entry["colors"]
  24. except KeyError:
  25. self.colors = ["Unknown"]
  26.  
  27. def get_card_type_value(self):
  28. if 'Artifact' in self.card_type:
  29. return 6
  30. if 'Land' in self.card_type:
  31. return 7
  32. if len(self.colors) > 1:
  33. return 5
  34. else:
  35. return Card.type_values[self.colors[0]]
  36.  
  37. def __lt__(self, other):
  38. selfval = self.get_card_type_value()
  39. othval = other.get_card_type_value()
  40. if selfval == othval:
  41. return self.name < other.name
  42. else:
  43. return selfval < othval
  44.  
  45. def __gt__(self, other):
  46. return other < self
  47.  
  48.  
  49. def __eq__(self, other):
  50. """Override the default Equals behavior"""
  51. if isinstance(other, self.__class__):
  52. return (self.name == other.name and self.set_id == other.set_id and self.is_foil == other.is_foil and self.language == other.language)
  53. return False
  54.  
  55. def __hash__(self):
  56. return self.name.__hash__() ^ self.set_id.__hash__() ^ self.is_foil.__hash__() ^ self.language.__hash__()
  57.  
  58. def get_quality_string(self):
  59. set_str = self.set if self.set_id in Card.bad_ids else self.set_id
  60. if self.is_foil:
  61. return set_str + ', Foil'
  62. else:
  63. return set_str
  64.  
  65. if __name__ == "__main__":
  66. with open('AllCards.json') as data_file:
  67. json_data = json.load(data_file)
  68.  
  69. full_card_list = []
  70. with open('puca.csv', 'r') as f:
  71. reader = csv.reader(f)
  72. full_card_list = list(reader)
  73. card_list = [Card(l[1], l[2], l[4], l[5], l[7]) for l in full_card_list[1:]]
  74. #compact the list
  75.  
  76. counter = collections.Counter(card_list)
  77. card_list = list(counter.keys())
  78.  
  79. for card in card_list:
  80. card.count = counter[card]
  81. card_list.sort()
  82. with open('output.txt', 'w') as f:
  83. curr_value = 0
  84. for card in card_list:
  85. if curr_value < card.get_card_type_value():
  86. curr_value = card.get_card_type_value()
  87. f.write('\n')
  88. if card.count > 1:
  89. name = '{0}x {1}'.format(card.count, card.name)
  90. else:
  91. name = card.name
  92. str_to_do = '{0} ({1})\n'.format(name, card.get_quality_string())
  93. print(str_to_do)
  94. f.write(str_to_do)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement