Removed the usage of inquirerpy for now.

It's asyncio routine seemed to interfere with scrython's
This commit is contained in:
mwisnowski 2024-12-20 22:02:35 -08:00
parent 8b5cfd97bc
commit 3ff3e5f686

View file

@ -11,19 +11,15 @@ from fuzzywuzzy import fuzz, process # type: ignore
from settings import csv_directory from settings import csv_directory
from setup import determine_commanders, set_lands from setup import determine_commanders, set_lands
print('Would you like to leverage Scrython for pricing information?') try:
question = [
inquirer.Confirm(
'scrython',
)
]
answer = inquirer.prompt(question)
choice = answer['scrython']
if choice:
use_scrython = True
import scrython # type: ignore import scrython # type: ignore
else: use_scrython = True
except ImportError:
scrython = None
use_scrython = False use_scrython = False
print("Scrython is not installed. Some pricing features will be unavailable.")
print(use_scrython)
pd.set_option('display.max_columns', None) pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None) pd.set_option('display.max_rows', None)
@ -97,6 +93,52 @@ class DeckBuilder:
# Battles # Battles
self.battle_cards = [] self.battle_cards = []
def questionnaire(self, inq_type, inq_default='', inq_choices=[]):
if inq_type == 'Text':
question = [
inquirer.Text('text')
]
result = inquirer.prompt(question)['text']
while len(result) <= 0:
question = [
inquirer.Text('text',
message='Input cannot be empty')
]
result = inquirer.prompt(question)['text']
return result
elif inq_type == 'Number':
question = [
inquirer.Text('number',
default=inq_default)
]
result = int(inquirer.prompt(question)['number'])
while type(result) is not int:
question = [
inquirer.Text('number',
default=inq_default)
]
result = inquirer.prompt(question)['number']
return result
elif inq_type == 'Confirm':
question = [
inquirer.Confirm('confirm',
default=inq_default),
]
result = inquirer.prompt(question)['confirm']
return result
elif inq_type == 'Choice':
question = [
inquirer.List('selection',
choices=inq_choices)
]
result = inquirer.prompt(question)['selection']
return result
raise ValueError(f"Unsupported inq_type: {inq_type}")
def price_check(self, card_name): def price_check(self, card_name):
card = scrython.cards.Named(fuzzy=f'{card_name}') card = scrython.cards.Named(fuzzy=f'{card_name}')
card_price = card.prices('usd') card_price = card.prices('usd')
@ -118,14 +160,7 @@ class DeckBuilder:
commander_chosen = False commander_chosen = False
while not commander_chosen: while not commander_chosen:
print('Enter a card name to be your commander, note that at this time only cards that have the \'Creature\' type may be chosen') print('Enter a card name to be your commander, note that at this time only cards that have the \'Creature\' type may be chosen')
question = [ card_choice = self.questionnaire('Text', '')
inquirer.Text(
'card_prompt',
message=''
)
]
answer = inquirer.prompt(question)
card_choice = answer['card_prompt']
# Logic to find the card in the commander_cards csv, then display it's information # Logic to find the card in the commander_cards csv, then display it's information
# If the card can't be found, or doesn't have enough of a match score, display a # If the card can't be found, or doesn't have enough of a match score, display a
@ -143,13 +178,7 @@ class DeckBuilder:
fuzzy_card_choices = process.extract(card_choice, df['name'], limit=5) fuzzy_card_choices = process.extract(card_choice, df['name'], limit=5)
fuzzy_card_choices.append('Neither') fuzzy_card_choices.append('Neither')
print(fuzzy_card_choices) print(fuzzy_card_choices)
question = [ fuzzy_card_choice = self.questionnaire('Choice', inq_choices=fuzzy_card_choices)
inquirer.List('choices',
choices=fuzzy_card_choices,
carousel=True)
]
answer = inquirer.prompt(question)
fuzzy_card_choice = answer['choices']
if fuzzy_card_choice != 'Neither': if fuzzy_card_choice != 'Neither':
fuzzy_card_choice = fuzzy_card_choice[0] fuzzy_card_choice = fuzzy_card_choice[0]
print(fuzzy_card_choice) print(fuzzy_card_choice)
@ -166,18 +195,13 @@ class DeckBuilder:
self.commander_df = pd.DataFrame(df_dict) self.commander_df = pd.DataFrame(df_dict)
# Confirm if card entered was correct # Confirm if card entered was correct
correct_commander = [ commander_confirmed = self.questionnaire('Confirm', True)
inquirer.Confirm(
'commander',
)
]
confirm_commander = inquirer.prompt(correct_commander)
commander_confirmed = confirm_commander['commander']
# If correct, set it as the commander # If correct, set it as the commander
if commander_confirmed: if commander_confirmed:
commander_chosen = True commander_chosen = True
self.commander_info = df_dict self.commander_info = df_dict
self.commander = self.commander_df.at[0, 'name'] self.commander = self.commander_df.at[0, 'name']
self.price_check(self.commander)
break break
#print(self.commander) #print(self.commander)
else: else:
@ -414,13 +438,7 @@ class DeckBuilder:
# Choose a primary theme # Choose a primary theme
print('Choose a primary theme for your commander deck.\n' print('Choose a primary theme for your commander deck.\n'
'This will be the "focus" of the deck, in a kindred deck this will typically be a creature type for example.') 'This will be the "focus" of the deck, in a kindred deck this will typically be a creature type for example.')
question = [ choice = self.questionnaire('Choice', inq_choices=themes)
inquirer.List('theme',
choices=themes,
carousel=True)
]
answer = inquirer.prompt(question)
choice = answer['theme']
self.primary_theme = choice self.primary_theme = choice
themes.remove(choice) themes.remove(choice)
themes.append('Stop Here') themes.append('Stop Here')
@ -432,23 +450,11 @@ class DeckBuilder:
# Secondary theme # Secondary theme
print('Choose a secondary theme for your commander deck.\n' print('Choose a secondary theme for your commander deck.\n'
'This will typically be a secondary focus, like card draw for Spellslinger, or +1/+1 counters for Aggro.') 'This will typically be a secondary focus, like card draw for Spellslinger, or +1/+1 counters for Aggro.')
question = [ choice = self.questionnaire('Choice', inq_choices=themes)
inquirer.List('theme',
choices=themes,
carousel=True)
]
answer = inquirer.prompt(question)
choice = answer['theme']
while True: while True:
if choice == 'Stop Here': if choice == 'Stop Here':
print('You\'ve only selected one theme, are you sure you want to stop?\n') print('You\'ve only selected one theme, are you sure you want to stop?\n')
confirm_themes = [ confirm_done = self.questionnaire('Confirm', 'False')
inquirer.Confirm(
'done',
)
]
answer = inquirer.prompt(confirm_themes)
confirm_done = answer['done']
if confirm_done: if confirm_done:
secondary_theme_chosen = True secondary_theme_chosen = True
self.secondary_theme = False self.secondary_theme = False
@ -469,23 +475,11 @@ class DeckBuilder:
# Tertiary theme # Tertiary theme
print('Choose a tertiary theme for your commander deck.\n' print('Choose a tertiary theme for your commander deck.\n'
'This will typically be a tertiary focus, or just something else to do that your commander is good at.') 'This will typically be a tertiary focus, or just something else to do that your commander is good at.')
question = [ choice = self.questionnaire('Choice', inq_choices=themes)
inquirer.List('theme',
choices=themes,
carousel=True)
]
answer = inquirer.prompt(question)
choice = answer['theme']
while True: while True:
if choice == 'Stop Here': if choice == 'Stop Here':
print('You\'ve only selected two themes, are you sure you want to stop?\n') print('You\'ve only selected two themes, are you sure you want to stop?\n')
confirm_themes = [ confirm_done = self.questionnaire('Confirm', False)
inquirer.Confirm(
'done',
)
]
answer = inquirer.prompt(confirm_themes)
confirm_done = answer['done']
if confirm_done: if confirm_done:
tertiary_theme_chosen = True tertiary_theme_chosen = True
self.tertiary_theme = False self.tertiary_theme = False
@ -507,47 +501,22 @@ class DeckBuilder:
if use_scrython: if use_scrython:
print('Would you like to set an intended max price of the deck?\n' print('Would you like to set an intended max price of the deck?\n'
'There will be some leeway of ~10%, with a couple alternative options provided.') 'There will be some leeway of ~10%, with a couple alternative options provided.')
question = [ choice = self.questionnaire('Confirm', False)
inquirer.Confirm(
'scrython',
)
]
answer = inquirer.prompt(question)
choice = answer['scrython']
if choice: if choice:
self.set_max_deck_price = True self.set_max_deck_price = True
print('What would you like the max price to be?') print('What would you like the max price to be?')
question = [ self.max_deck_price = self.questionnaire('Number', '400')
inquirer.Text(
'max_price',
default='400'
)
]
answer = inquirer.prompt(question)
self.max_deck_price = float(answer['max_price'])
else: else:
self.set_max_deck_price = False self.set_max_deck_price = False
print('Would you like to set a max price per card?\n' print('Would you like to set a max price per card?\n'
'There will be some leeway of ~10% when choosing cards and you can choose to keep it or not.') 'There will be some leeway of ~10% when choosing cards and you can choose to keep it or not.')
question = [ choice = self.questionnaire('Confirm', False)
inquirer.Confirm(
'scrython',
)
]
answer = inquirer.prompt(question)
choice = answer['scrython']
if choice: if choice:
self.set_max_card_price = True self.set_max_card_price = True
print('What would you like the max price to be?') print('What would you like the max price to be?')
question = [ answer = self.questionnaire('Number', '20')
inquirer.Text( self.max_card_price = answer
'max_price',
default='20'
)
]
answer = inquirer.prompt(question)
self.max_card_price = float(answer['max_price'])
else: else:
self.set_max_card_price = False self.set_max_card_price = False
@ -555,14 +524,8 @@ class DeckBuilder:
print('How many pieces of ramp would you like to include?\n' print('How many pieces of ramp would you like to include?\n'
'You\'re gonna want a decent amount of ramp, both getting lands or mana rocks/dorks.\n' 'You\'re gonna want a decent amount of ramp, both getting lands or mana rocks/dorks.\n'
'A good baseline is 8-12, scaling up with average CMC.') 'A good baseline is 8-12, scaling up with average CMC.')
question = [ answer = self.questionnaire('Number', '8')
inquirer.Text( self.ideal_ramp = int(answer)
'ramp_prompt',
default='8'
)
]
answer = inquirer.prompt(question)
self.ideal_ramp = int(answer['ramp_prompt'])
self.free_slots -= self.ideal_ramp self.free_slots -= self.ideal_ramp
# Determine ideal land count # Determine ideal land count
@ -570,29 +533,25 @@ class DeckBuilder:
'Before ramp is taken into account, 38-40 would be "normal" for a deck. I personally use 35.\n' 'Before ramp is taken into account, 38-40 would be "normal" for a deck. I personally use 35.\n'
'Broadly speaking, for every mana produced per 3 mana spent on ramp could reduce land count by 1.\n' 'Broadly speaking, for every mana produced per 3 mana spent on ramp could reduce land count by 1.\n'
'If you\'re playing landfall, probably consider 40 as baseline before ramp.') 'If you\'re playing landfall, probably consider 40 as baseline before ramp.')
question = [ answer = self.questionnaire('Number', '35')
inquirer.Text( self.ideal_land_count = int(answer)
'land_prompt',
default='35'
)
]
answer = inquirer.prompt(question)
self.ideal_land_count = int(answer['land_prompt'])
self.free_slots -= self.ideal_land_count self.free_slots -= self.ideal_land_count
# Determine minimum basics to have
print('How many basic lands would you like to have at minimum?\n'
'This can vary widely depending on your commander, colors in color identity, and what you want to do.\n'
'Some decks may be fine with as low as 10, others may want 25.')
answer = self.questionnaire('Number', '20')
self.min_basics = int(answer)
# Determine ideal creature count # Determine ideal creature count
print('How many creatures would you like to include?\n' print('How many creatures would you like to include?\n'
'Something like 25-30 would be a good starting point.\n' 'Something like 25-30 would be a good starting point.\n'
'If you\'re going for a kindred theme, going past 30 is likely normal.\n' 'If you\'re going for a kindred theme, going past 30 is likely normal.\n'
'Also be sure to take into account token generation, but remember you\'ll want enough to stay safe') 'Also be sure to take into account token generation, but remember you\'ll want enough to stay safe')
question = [ answer = self.questionnaire('Number', '25')
inquirer.Text( self.ideal_creature_count = int(answer)
'creature_prompt',
default='25'
)
]
answer = inquirer.prompt(question)
self.ideal_creature_count = int(answer['creature_prompt'])
self.free_slots -= self.ideal_creature_count self.free_slots -= self.ideal_creature_count
# Determine spot/targetted removal # Determine spot/targetted removal
@ -600,42 +559,24 @@ class DeckBuilder:
'A good starting point is about 8-12 pieces of spot removal.\n' 'A good starting point is about 8-12 pieces of spot removal.\n'
'Counterspells can be consisdered proactive removal and protection.\n' 'Counterspells can be consisdered proactive removal and protection.\n'
'If you\'re going spellslinger, more would be a good idea as you might have less cretaures.') 'If you\'re going spellslinger, more would be a good idea as you might have less cretaures.')
question = [ answer = self.questionnaire('Number', '10')
inquirer.Text( self.ideal_removal = int(answer)
'removal_prompt',
default='10'
)
]
answer = inquirer.prompt(question)
self.ideal_removal = int(answer['removal_prompt'])
self.free_slots -= self.ideal_removal self.free_slots -= self.ideal_removal
# Determine board wipes # Determine board wipes
print('How many board wipesyou like to include?\n' print('How many board wipes would you like to include?\n'
'Somewhere around 2-3 is good to help eliminate threats, but also prevent the game from running long\n.' 'Somewhere around 2-3 is good to help eliminate threats, but also prevent the game from running long\n.'
'This can include damaging wipes like \'Blasphemous Act\' or toughness reduction like \'Meathook Massacre\'.') 'This can include damaging wipes like \'Blasphemous Act\' or toughness reduction like \'Meathook Massacre\'.')
question = [ answer = self.questionnaire('Number', '2')
inquirer.Text( self.ideal_wipes = int(answer)
'board_wipe_prompt',
default='2'
)
]
answer = inquirer.prompt(question)
self.ideal_wipes = int(answer['board_wipe_prompt'])
self.free_slots -= self.ideal_wipes self.free_slots -= self.ideal_wipes
# Determine card advantage # Determine card advantage
print('How many pieces of card advantage would you like to include?\n' print('How many pieces of card advantage would you like to include?\n'
'10 pieces of card advantage is good, up to 14 is better.\n' '10 pieces of card advantage is good, up to 14 is better.\n'
'Try to have a majority of it be non-conditional, and only have a couple of \'Rhystic Study\' style effects.') 'Try to have a majority of it be non-conditional, and only have a couple of \'Rhystic Study\' style effects.')
question = [ answer = self.questionnaire('Number', '10')
inquirer.Text( self.ideal_card_advantage = int(answer)
'draw_prompt',
default='10'
)
]
answer = inquirer.prompt(question)
self.ideal_card_advantage = int(answer['draw_prompt'])
self.free_slots -= self.ideal_card_advantage self.free_slots -= self.ideal_card_advantage
# Determine how many protection spells # Determine how many protection spells
@ -644,14 +585,8 @@ class DeckBuilder:
'Things that grant indestructible, hexproof, phase out, or event just counterspells.\n' 'Things that grant indestructible, hexproof, phase out, or event just counterspells.\n'
'This can be a widely variable ideal count, and can be as low as 5, and up past 15,\n' 'This can be a widely variable ideal count, and can be as low as 5, and up past 15,\n'
'it depends on your commander and how important your wincons are.') 'it depends on your commander and how important your wincons are.')
question = [ answer = self.questionnaire('Number', '8')
inquirer.Text( self.ideal_protection = int(answer)
'protection_prompt',
default='8'
)
]
answer = inquirer.prompt(question)
self.ideal_protection = int(answer['protection_prompt'])
self.free_slots -= self.ideal_protection self.free_slots -= self.ideal_protection
print(f'Free slots that aren\'t part of the ideals: {self.free_slots}') print(f'Free slots that aren\'t part of the ideals: {self.free_slots}')
@ -687,19 +622,6 @@ class DeckBuilder:
if len(self.colors) >= 3: if len(self.colors) >= 3:
pass pass
# Determine minimum basics to have
print('How many basic lands would you like to have at minimum?\n'
'This can vary widely depending on your commander, colors in color identity, and what you want to do.\n'
'Some decks may be fine with as low as 10, others may want 25.')
question = [
inquirer.Text(
'num_basics',
default='20'
)
]
answer = inquirer.prompt(question)
self.ideal_protection = int(answer['protection_prompt'])
self.add_misc_lands() self.add_misc_lands()
rows_to_drop = [] rows_to_drop = []
@ -811,14 +733,9 @@ class DeckBuilder:
print('How many fetch lands would you like to include?\n' print('How many fetch lands would you like to include?\n'
'For most decks you\'ll likely be good with 3 or 4, just enough to thin the deck and help ensure the color availability.\n' 'For most decks you\'ll likely be good with 3 or 4, just enough to thin the deck and help ensure the color availability.\n'
'If you\'re doing Landfall, more fetches would be recommended just to get as many Landfall triggers per turn.') 'If you\'re doing Landfall, more fetches would be recommended just to get as many Landfall triggers per turn.')
question = [ answer = self.questionnaire('Number', '5')
inquirer.Text(
'fetch_prompt', desired_fetches = int(answer)
default='5'
)
]
answer = inquirer.prompt(question)
desired_fetches = int(answer['fetch_prompt'])
chosen_fetches = [] chosen_fetches = []
generic_fetches = ['Evolving Wilds', 'Terramorphic Expanse', 'Shire Terrace', 'Escape Tunnel', 'Promising Vein','Myriad Landscape', 'Fabled Passage', 'Terminal Moraine'] generic_fetches = ['Evolving Wilds', 'Terramorphic Expanse', 'Shire Terrace', 'Escape Tunnel', 'Promising Vein','Myriad Landscape', 'Fabled Passage', 'Terminal Moraine']
@ -826,13 +743,16 @@ class DeckBuilder:
fetches_to_remove = generic_fetches fetches_to_remove = generic_fetches
# Adding in expensive fetches # Adding in expensive fetches
if (use_scrython and self.set_max_card_price): """if (use_scrython and self.set_max_card_price):
if self.price_check('Prismatic Vista') is None: if self.price_check('Prismatic Vista') <= self.max_card_price:
fetches_to_remove.append('Prismatic Vista') fetches_to_remove.append('Prismatic Vista')
fetches.append('Prismatic Vista') fetches.append('Prismatic Vista')
else: else:
fetches_to_remove.append('Prismatic Vista') fetches_to_remove.append('Prismatic Vista')
fetches.append('Prismatic Vista') pass
else:
fetches_to_remove.append('Prismatic Vista')
fetches.append('Prismatic Vista')"""
# White Fetches # White Fetches
if 'W' in self.colors: if 'W' in self.colors:
@ -1046,14 +966,8 @@ class DeckBuilder:
print('These are the fetch lands that have been found for you:') print('These are the fetch lands that have been found for you:')
print(chosen_fetches) print(chosen_fetches)
print('Do they look good for you?') print('Do they look good for you?')
question = [ answer = self.questionnaire('Confirm', True)
inquirer.Confirm( if not answer:
'yes',
)
]
answer = inquirer.prompt(question)
choice = answer['yes']
if not choice:
print('Reselecting fetches to use.') print('Reselecting fetches to use.')
chosen_fetches = [] chosen_fetches = []
@ -1061,13 +975,7 @@ class DeckBuilder:
fetches_to_add = [] fetches_to_add = []
while len(fetches_to_add) < desired_fetches: while len(fetches_to_add) < desired_fetches:
print(f'Please choose {desired_fetches} of them to add to your deck.') print(f'Please choose {desired_fetches} of them to add to your deck.')
question = [ choice = self.questionnaire('Choice', inq_choices=chosen_fetches)
inquirer.List('theme',
choices=chosen_fetches,
carousel=True)
]
answer = inquirer.prompt(question)
choice = answer['theme']
fetches_to_add.append(choice) fetches_to_add.append(choice)
chosen_fetches.remove(choice) chosen_fetches.remove(choice)
fetches_chosen = True fetches_chosen = True
@ -1283,13 +1191,7 @@ class DeckBuilder:
# Determine if using the dual-type lands # Determine if using the dual-type lands
print('Would you like to include dual-type lands (i.e. lands that count as both a Plains and a Swamp for example)?') print('Would you like to include dual-type lands (i.e. lands that count as both a Plains and a Swamp for example)?')
question = [ choice = self.questionnaire('Confirm', True)
inquirer.Confirm(
'yes',
)
]
answer = inquirer.prompt(question)
choice = answer['yes']
# Add the Duals to a list # Add the Duals to a list