-
Notifications
You must be signed in to change notification settings - Fork 0
/
decklist.py
62 lines (53 loc) · 2.56 KB
/
decklist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from mtgsdk import Card
class Decklist:
def __init__(self, decklist, decklist_name):
self.decklist = decklist
self.decklist_name = decklist_name
# This will convert the cards from the multiverse_id to the Card class from mtgsdk,if the decklist is a previously saved decklist
if self.decklist != []:
for count, card in enumerate(self.decklist):
self.decklist[count] = Card.find(card)
print(self.decklist[count])
def save_decklist(self, card):
with open(f"saved_decklists\\{self.decklist_name}.txt", "a") as file:
file.write(card.id + '\n')
def add_to_decklist(self):
while True:
card_to_add = input("Please input the name of the card you would like to add: ").title().strip()
if "The" in card_to_add and not card_to_add.startswith("The "):
card_to_add = card_to_add.replace("The", "the")
try:
print(f"Searching for {card_to_add}")
cards = Card.where(name=card_to_add).all()
print(f"Found {len(cards)} cards")
card_added = False
for card in cards:
try:
# Making sure the card name is an exact match, otherwise it could add a card with part of the name
if card.name == card_to_add:
print(card.name)
print(card.set)
print(card.id)
self.decklist.append(card)
self.save_decklist(card)
print(f"{card.name} added to decklist")
card_added = True
break
else:
print(f"Similar card found: {card.name}, {card.set}")
except AttributeError as e: # Some versions dont have a multiverse_id, so this will skip those
print(f"Attribute error {e}")
continue
except Exception as error:
print("Decklist.add_to_decklist error:", error)
except:
print("it broke")
if card_added:
break
else:
print(f"Unable to find {card_to_add}, please try again and make sure the card is entered correctly")
def remove_from_decklist():
pass
def show_current_decklist(self):
for card in self.decklist:
print(card.name)