mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-12-17 16:10:12 +01:00
Removed need to create seperate land_cards file in setup
Adjusted tagger to keep the 'layout' and 'side' columns
This commit is contained in:
parent
ae83d0f66f
commit
1f8beeadef
2 changed files with 4 additions and 72 deletions
67
setup.py
67
setup.py
|
|
@ -52,64 +52,6 @@ def filter_by_color(df, column_name, value, new_csv_name):
|
||||||
|
|
||||||
filtered_df.to_csv(new_csv_name, index=False)
|
filtered_df.to_csv(new_csv_name, index=False)
|
||||||
|
|
||||||
def set_lands():
|
|
||||||
print('Generating land_cards.csv.')
|
|
||||||
# Filter dataframe
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
with open(f'{csv_directory}/cards.csv', 'r', encoding='utf-8'):
|
|
||||||
print('cards.csv exists.')
|
|
||||||
break
|
|
||||||
except FileNotFoundError:
|
|
||||||
# If the cards.csv file does not exist or can't be found, pull it from mtgjson.com
|
|
||||||
print('cards.csv not found, downloading from mtgjson')
|
|
||||||
url = 'https://mtgjson.com/api/v5/csv/cards.csv'
|
|
||||||
r = requests.get(url)
|
|
||||||
with open(f'{csv_directory}/cards.csv', 'wb') as outputfile:
|
|
||||||
outputfile.write(r.content)
|
|
||||||
|
|
||||||
# Load cards.csv file into pandas dataframe so it can be further broken down
|
|
||||||
df = pd.read_csv(f'{csv_directory}/cards.csv', low_memory=False)
|
|
||||||
|
|
||||||
legendary_options = ['Land']
|
|
||||||
df['colorIdentity'] = df['colorIdentity'].fillna('Colorless')
|
|
||||||
filtered_df = df[df['type'].str.contains('|'.join(legendary_options))]
|
|
||||||
"""
|
|
||||||
Save the filtered dataframe to a new csv file, and narrow down/rearranges the columns it
|
|
||||||
keeps to increase readability/trim some extra data.
|
|
||||||
Additionally attempts to remove as many duplicates (including cards with reversible prints,
|
|
||||||
as well as taking out Arena-only cards.
|
|
||||||
"""
|
|
||||||
rows_to_drop = []
|
|
||||||
non_legel_sets = ['PHTR', 'PH17', 'PH18' ,'PH19', 'PH20', 'PH21', 'UGL', 'UND', 'UNH', 'UST',]
|
|
||||||
for index, row in filtered_df.iterrows():
|
|
||||||
for illegal_set in non_legel_sets:
|
|
||||||
if illegal_set in row['printings']:
|
|
||||||
rows_to_drop.append(index)
|
|
||||||
|
|
||||||
filtered_df = filtered_df.drop(rows_to_drop)
|
|
||||||
|
|
||||||
filtered_df.sort_values('name')
|
|
||||||
filtered_df = filtered_df.loc[filtered_df['layout'] != 'reversible_card']
|
|
||||||
filtered_df = filtered_df[filtered_df['availability'].str.contains('paper')]
|
|
||||||
filtered_df = filtered_df.loc[filtered_df['promoTypes'] != 'playtest']
|
|
||||||
filtered_df = filtered_df.loc[filtered_df['securityStamp'] != 'heart']
|
|
||||||
filtered_df = filtered_df.loc[filtered_df['securityStamp'] != 'acorn']
|
|
||||||
|
|
||||||
for card in banned_cards:
|
|
||||||
filtered_df = filtered_df[~filtered_df['name'].str.contains(card)]
|
|
||||||
|
|
||||||
card_types = ['Plane —', 'Conspiracy', 'Vanguard', 'Scheme', 'Phenomenon', 'Stickers', 'Attraction', 'Hero', 'Contraption']
|
|
||||||
for card_type in card_types:
|
|
||||||
filtered_df = filtered_df[~filtered_df['type'].str.contains(card_type)]
|
|
||||||
filtered_df['faceName'] = filtered_df['faceName'].fillna(filtered_df['name'])
|
|
||||||
filtered_df.drop_duplicates(subset='faceName', keep='first', inplace=True)
|
|
||||||
columns_to_keep = ['name', 'faceName','edhrecRank','colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'layout', 'text', 'power', 'toughness', 'keywords']
|
|
||||||
filtered_df = filtered_df[columns_to_keep]
|
|
||||||
filtered_df.sort_values(by='edhrecRank', inplace=True)
|
|
||||||
filtered_df.to_csv(f'{csv_directory}/land_cards.csv', index=False)
|
|
||||||
print('land_cards.csv file generated.')
|
|
||||||
|
|
||||||
def determine_commanders():
|
def determine_commanders():
|
||||||
print('Generating commander_cards.csv, containing all cards elligible to be commanders.')
|
print('Generating commander_cards.csv, containing all cards elligible to be commanders.')
|
||||||
# Filter dataframe
|
# Filter dataframe
|
||||||
|
|
@ -214,9 +156,6 @@ def initial_setup():
|
||||||
# Once by-color lists have been made, Determine legendary creatures
|
# Once by-color lists have been made, Determine legendary creatures
|
||||||
determine_commanders()
|
determine_commanders()
|
||||||
|
|
||||||
# Lastly, create a file with all lands, or cards that have a land on at least one face
|
|
||||||
set_lands()
|
|
||||||
|
|
||||||
# Once Legendary creatures are determined, generate staple lists
|
# Once Legendary creatures are determined, generate staple lists
|
||||||
# generate_staple_lists()
|
# generate_staple_lists()
|
||||||
|
|
||||||
|
|
@ -257,9 +196,6 @@ def regenerate_csvs_all():
|
||||||
# Once files are regenerated, create a new legendary list
|
# Once files are regenerated, create a new legendary list
|
||||||
determine_commanders()
|
determine_commanders()
|
||||||
|
|
||||||
# Lastly, create a file with all lands, or cards that have a land on at least one face
|
|
||||||
set_lands()
|
|
||||||
|
|
||||||
def regenerate_csv_by_color(color):
|
def regenerate_csv_by_color(color):
|
||||||
"""
|
"""
|
||||||
Pull the original cards.csv file and remake the {color}_cards.csv files
|
Pull the original cards.csv file and remake the {color}_cards.csv files
|
||||||
|
|
@ -289,9 +225,6 @@ def regenerate_csv_by_color(color):
|
||||||
# Once files are regenerated, create a new legendary list
|
# Once files are regenerated, create a new legendary list
|
||||||
determine_commanders()
|
determine_commanders()
|
||||||
|
|
||||||
# Lastly, create a file with all lands, or cards that have a land on at least one face
|
|
||||||
set_lands()
|
|
||||||
|
|
||||||
def add_tags():
|
def add_tags():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ def kindred_tagging(df, color):
|
||||||
print(f'Creature types from text set in {color}_cards.csv.\n')
|
print(f'Creature types from text set in {color}_cards.csv.\n')
|
||||||
|
|
||||||
# Overwrite file with creature type tags
|
# Overwrite file with creature type tags
|
||||||
columns_to_keep = ['name', 'faceName','edhrecRank', 'colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'creatureTypes', 'text', 'power', 'toughness', 'keywords']
|
columns_to_keep = ['name', 'faceName','edhrecRank', 'colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'creatureTypes', 'text', 'power', 'toughness', 'keywords', 'layout', 'side']
|
||||||
df = df[columns_to_keep]
|
df = df[columns_to_keep]
|
||||||
df.to_csv(f'{csv_directory}/{color}_cards.csv', index=False)
|
df.to_csv(f'{csv_directory}/{color}_cards.csv', index=False)
|
||||||
print(f'\nCreature types tagged on {color}_cards.csv.\n')
|
print(f'\nCreature types tagged on {color}_cards.csv.\n')
|
||||||
|
|
@ -194,7 +194,7 @@ def create_theme_tags(df, color):
|
||||||
df['themeTags'] = [[] for _ in range(len(df))]
|
df['themeTags'] = [[] for _ in range(len(df))]
|
||||||
|
|
||||||
# Organize it's location
|
# Organize it's location
|
||||||
columns_to_keep = ['name', 'faceName','edhrecRank', 'colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'creatureTypes', 'text', 'power', 'toughness', 'keywords', 'themeTags']
|
columns_to_keep = ['name', 'faceName','edhrecRank', 'colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'creatureTypes', 'text', 'power', 'toughness', 'keywords', 'themeTags', 'layout', 'side']
|
||||||
df = df[columns_to_keep]
|
df = df[columns_to_keep]
|
||||||
|
|
||||||
# Overwrite original file
|
# Overwrite original file
|
||||||
|
|
@ -265,7 +265,6 @@ def add_creatures_to_tags(df, color):
|
||||||
if pd.isna(row['text']):
|
if pd.isna(row['text']):
|
||||||
continue
|
continue
|
||||||
theme_tags = row['themeTags']
|
theme_tags = row['themeTags']
|
||||||
#if all_kindred in row['text'].lower():
|
|
||||||
for item in all_kindred:
|
for item in all_kindred:
|
||||||
if item in row['text'].lower():
|
if item in row['text'].lower():
|
||||||
if 'Kindred Support' not in theme_tags:
|
if 'Kindred Support' not in theme_tags:
|
||||||
|
|
@ -298,7 +297,7 @@ def sort_theme_tags(df, color):
|
||||||
|
|
||||||
df['themeTags'] = df['themeTags'].apply(sort_list)
|
df['themeTags'] = df['themeTags'].apply(sort_list)
|
||||||
|
|
||||||
columns_to_keep = ['name', 'faceName','edhrecRank', 'colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'creatureTypes', 'text', 'power', 'toughness', 'keywords', 'themeTags']
|
columns_to_keep = ['name', 'faceName','edhrecRank', 'colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'creatureTypes', 'text', 'power', 'toughness', 'keywords', 'themeTags', 'layout', 'side']
|
||||||
df = df[columns_to_keep]
|
df = df[columns_to_keep]
|
||||||
print(f'Theme tags alphabetically sorted in {color}_cards.csv.\n')
|
print(f'Theme tags alphabetically sorted in {color}_cards.csv.\n')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue