diff --git a/cards.csv b/cards.csv index ff10110..18cb263 100644 --- a/cards.csv +++ b/cards.csv @@ -2,3 +2,37 @@ Card Name,Set Code,Collector Number,Quantity,Foil "Linda, Kandarian Queen",sld,1355,1,True "Vraska, Golgari Queen",sld,1702,1,False "Vraska, Golgari Queen",sld,1702,1,True +"Huatli, Radiant Champion",sld,1699,1,False +"Huatli, Radiant Champion",sld,1699,1,True +"Kiora, Behemoth Beckoner",sld,1700,1,False +"Kiora, Behemoth Beckoner",sld,1700,1,True +"Tezzeret, Master of the Bridge",sld,1701,1,False +"Tezzeret, Master of the Bridge",sld,1701,1,True +Sorin Markov,sld,1698,1,False +Sorin Markov,sld,1698,1,True +"Flubs, The Fool",blc,356,1,True +"Flubs, The Fool",blc,356,1,False +Pollenbright Druid,sld,776,1,True +Frilled Mystic,sld,786,1,True +"Obeka, Brute Chronolgoist",sld,1579,1,False +Dire Undercurrents,sld,1578,1,False +Black Market,sld,1577,1,False +"Jace, Wielder of Mysteries",sld,1576,1,False +Reconnasissance,sld,1575,1,False +"Yargle, Glutton of Urborg",sld,1542,1,False +"Adrix and Nev, Twincasters",sld,1544,1,False +Coveted Jewel,sld,799,1,False +Sakashima of a Thousand Faces,sld,1541,1,False +"Krark, The Thumbless",sld,1543,1,False +Arcance Denial,sld,1545,1,False +Nightscape Familiar,sld,1546,1,False +Rain of Filth,sld,1547,1,False +Simian Spirit Guide,sld,1548,1,False +Prince of Thralls,sld,1549,1,False +Felidar Guardian,sld,1487,1,False +Peregrine Drake,sld,1488,1,False +Serpent of Yawning Depths,sld,1489,1,False +Scourage of Valkas,sld,1490,1,False +Voracious Hydra,sld,1491,1,False +The Scorpion God,sld,904,1,True +"Vilis, Broker of Blood",sld,1567,1,False diff --git a/cli_cards.py b/cli_cards.py new file mode 100644 index 0000000..504e490 --- /dev/null +++ b/cli_cards.py @@ -0,0 +1,60 @@ +import csv +import os +import argparse + +# Function to append a card entry to the CSV file +def add_card_to_csv(csv_path, card_name, set_code, collector_number, quantity, foil): + file_exists = os.path.isfile(csv_path) + + with open(csv_path, mode='a', newline='') as file: + writer = csv.writer(file) + + # Write header if the file doesn't exist + if not file_exists: + writer.writerow(['Card Name', 'Set Code', 'Collector Number', 'Quantity', 'Foil']) + + # Append the card data + writer.writerow([card_name, set_code, collector_number, quantity, foil]) + + print(f"Added {quantity}x {card_name} from set {set_code} with collector number {collector_number} (Foil: {foil}) to {csv_path}.") + +# Function to parse and add multiple cards +def add_multiple_cards(csv_path, card_entries): + for entry in card_entries: + card_name, set_code, collector_number, quantity, foil = entry + add_card_to_csv(csv_path, card_name, set_code, collector_number, quantity, foil) + +# Main function to handle command-line arguments +def main(): + parser = argparse.ArgumentParser(description="Add one or more Magic: The Gathering cards to a CSV file.") + + parser.add_argument('csv_path', + help="The path to the CSV file where the card data will be stored. If the file does not exist, it will be created.") + + # Allow multiple --card entries + parser.add_argument('--card', + action='append', + nargs=5, + metavar=('Card_Name', 'Set_Code', 'Collector_Number', 'Quantity', 'Foil'), + help=("Add a card to the CSV file. " + "Each card entry should be specified in the following format: " + "Card_Name Set_Code Collector_Number Quantity Foil. " + "Foil should be 'True' or 'False' indicating if the card is foil or not. " + "This option can be used multiple times to add multiple cards in one command.")) + + args = parser.parse_args() + + if args.card: + card_entries = [] + for card in args.card: + card_name, set_code, collector_number, quantity, foil = card + quantity = int(quantity) + foil = foil.lower() == 'true' # Convert the foil input to a boolean + card_entries.append((card_name, set_code, collector_number, quantity, foil)) + + add_multiple_cards(args.csv_path, card_entries) + else: + print("No cards provided. Use the --card option to add cards.") + +if __name__ == "__main__": + main() diff --git a/downloaded_images/blc_Flubs, The Fool_Flubs, the Fool.jpg b/downloaded_images/blc_Flubs, The Fool_Flubs, the Fool.jpg new file mode 100644 index 0000000..4f20a49 Binary files /dev/null and b/downloaded_images/blc_Flubs, The Fool_Flubs, the Fool.jpg differ diff --git a/downloaded_images/sld_Adrix and Nev, Twincasters_Adrix and Nev, Twincasters.jpg b/downloaded_images/sld_Adrix and Nev, Twincasters_Adrix and Nev, Twincasters.jpg new file mode 100644 index 0000000..69e732b Binary files /dev/null and b/downloaded_images/sld_Adrix and Nev, Twincasters_Adrix and Nev, Twincasters.jpg differ diff --git a/downloaded_images/sld_Arcance Denial_Arcane Denial.jpg b/downloaded_images/sld_Arcance Denial_Arcane Denial.jpg new file mode 100644 index 0000000..37a186a Binary files /dev/null and b/downloaded_images/sld_Arcance Denial_Arcane Denial.jpg differ diff --git a/downloaded_images/sld_Black Market_Black Market.jpg b/downloaded_images/sld_Black Market_Black Market.jpg new file mode 100644 index 0000000..e983440 Binary files /dev/null and b/downloaded_images/sld_Black Market_Black Market.jpg differ diff --git a/downloaded_images/sld_Coveted Jewel_Coveted Jewel.jpg b/downloaded_images/sld_Coveted Jewel_Coveted Jewel.jpg new file mode 100644 index 0000000..0d2b07e Binary files /dev/null and b/downloaded_images/sld_Coveted Jewel_Coveted Jewel.jpg differ diff --git a/downloaded_images/sld_Dire Undercurrents_Dire Undercurrents.jpg b/downloaded_images/sld_Dire Undercurrents_Dire Undercurrents.jpg new file mode 100644 index 0000000..6b5c9f3 Binary files /dev/null and b/downloaded_images/sld_Dire Undercurrents_Dire Undercurrents.jpg differ diff --git a/downloaded_images/sld_Felidar Guardian_Felidar Guardian.jpg b/downloaded_images/sld_Felidar Guardian_Felidar Guardian.jpg new file mode 100644 index 0000000..33d53fd Binary files /dev/null and b/downloaded_images/sld_Felidar Guardian_Felidar Guardian.jpg differ diff --git a/downloaded_images/sld_Frilled Mystic_Frilled Mystic.jpg b/downloaded_images/sld_Frilled Mystic_Frilled Mystic.jpg new file mode 100644 index 0000000..549ccf9 Binary files /dev/null and b/downloaded_images/sld_Frilled Mystic_Frilled Mystic.jpg differ diff --git a/downloaded_images/sld_Huatli, Radiant Champion_Huatli, Radiant Champion.jpg b/downloaded_images/sld_Huatli, Radiant Champion_Huatli, Radiant Champion.jpg new file mode 100644 index 0000000..371b04b Binary files /dev/null and b/downloaded_images/sld_Huatli, Radiant Champion_Huatli, Radiant Champion.jpg differ diff --git a/downloaded_images/sld_Jace, Wielder of Mysteries_Jace, Wielder of Mysteries.jpg b/downloaded_images/sld_Jace, Wielder of Mysteries_Jace, Wielder of Mysteries.jpg new file mode 100644 index 0000000..c7336e2 Binary files /dev/null and b/downloaded_images/sld_Jace, Wielder of Mysteries_Jace, Wielder of Mysteries.jpg differ diff --git a/downloaded_images/sld_Kiora, Behemoth Beckoner_Kiora, Behemoth Beckoner.jpg b/downloaded_images/sld_Kiora, Behemoth Beckoner_Kiora, Behemoth Beckoner.jpg new file mode 100644 index 0000000..a9961ea Binary files /dev/null and b/downloaded_images/sld_Kiora, Behemoth Beckoner_Kiora, Behemoth Beckoner.jpg differ diff --git a/downloaded_images/sld_Krark, The Thumbless_Krark, the Thumbless.jpg b/downloaded_images/sld_Krark, The Thumbless_Krark, the Thumbless.jpg new file mode 100644 index 0000000..301e4a4 Binary files /dev/null and b/downloaded_images/sld_Krark, The Thumbless_Krark, the Thumbless.jpg differ diff --git a/downloaded_images/Linda, Kandarian Queen_Varina, Lich Queen.jpg b/downloaded_images/sld_Linda, Kandarian Queen_Varina, Lich Queen.jpg similarity index 100% rename from downloaded_images/Linda, Kandarian Queen_Varina, Lich Queen.jpg rename to downloaded_images/sld_Linda, Kandarian Queen_Varina, Lich Queen.jpg diff --git a/downloaded_images/sld_Nightscape Familiar_Nightscape Familiar.jpg b/downloaded_images/sld_Nightscape Familiar_Nightscape Familiar.jpg new file mode 100644 index 0000000..629c9f0 Binary files /dev/null and b/downloaded_images/sld_Nightscape Familiar_Nightscape Familiar.jpg differ diff --git a/downloaded_images/sld_Obeka, Brute Chronolgoist_Obeka, Brute Chronologist.jpg b/downloaded_images/sld_Obeka, Brute Chronolgoist_Obeka, Brute Chronologist.jpg new file mode 100644 index 0000000..8f06cd1 Binary files /dev/null and b/downloaded_images/sld_Obeka, Brute Chronolgoist_Obeka, Brute Chronologist.jpg differ diff --git a/downloaded_images/sld_Peregrine Drake_Peregrine Drake.jpg b/downloaded_images/sld_Peregrine Drake_Peregrine Drake.jpg new file mode 100644 index 0000000..bfb20f5 Binary files /dev/null and b/downloaded_images/sld_Peregrine Drake_Peregrine Drake.jpg differ diff --git a/downloaded_images/sld_Pollenbright Druid_Pollenbright Druid.jpg b/downloaded_images/sld_Pollenbright Druid_Pollenbright Druid.jpg new file mode 100644 index 0000000..e944aca Binary files /dev/null and b/downloaded_images/sld_Pollenbright Druid_Pollenbright Druid.jpg differ diff --git a/downloaded_images/sld_Prince of Thralls_Prince of Thralls.jpg b/downloaded_images/sld_Prince of Thralls_Prince of Thralls.jpg new file mode 100644 index 0000000..659954c Binary files /dev/null and b/downloaded_images/sld_Prince of Thralls_Prince of Thralls.jpg differ diff --git a/downloaded_images/sld_Rain of Filth_Rain of Filth.jpg b/downloaded_images/sld_Rain of Filth_Rain of Filth.jpg new file mode 100644 index 0000000..cd67424 Binary files /dev/null and b/downloaded_images/sld_Rain of Filth_Rain of Filth.jpg differ diff --git a/downloaded_images/sld_Reconnasissance_Reconnaissance.jpg b/downloaded_images/sld_Reconnasissance_Reconnaissance.jpg new file mode 100644 index 0000000..3457526 Binary files /dev/null and b/downloaded_images/sld_Reconnasissance_Reconnaissance.jpg differ diff --git a/downloaded_images/sld_Sakashima of a Thousand Faces_Sakashima of a Thousand Faces.jpg b/downloaded_images/sld_Sakashima of a Thousand Faces_Sakashima of a Thousand Faces.jpg new file mode 100644 index 0000000..eec566d Binary files /dev/null and b/downloaded_images/sld_Sakashima of a Thousand Faces_Sakashima of a Thousand Faces.jpg differ diff --git a/downloaded_images/sld_Scourage of Valkas_Scourge of Valkas.jpg b/downloaded_images/sld_Scourage of Valkas_Scourge of Valkas.jpg new file mode 100644 index 0000000..a161a23 Binary files /dev/null and b/downloaded_images/sld_Scourage of Valkas_Scourge of Valkas.jpg differ diff --git a/downloaded_images/sld_Serpent of Yawning Depths_Serpent of Yawning Depths.jpg b/downloaded_images/sld_Serpent of Yawning Depths_Serpent of Yawning Depths.jpg new file mode 100644 index 0000000..ccf0dd3 Binary files /dev/null and b/downloaded_images/sld_Serpent of Yawning Depths_Serpent of Yawning Depths.jpg differ diff --git a/downloaded_images/sld_Simian Spirit Guide_Simian Spirit Guide.jpg b/downloaded_images/sld_Simian Spirit Guide_Simian Spirit Guide.jpg new file mode 100644 index 0000000..9a97900 Binary files /dev/null and b/downloaded_images/sld_Simian Spirit Guide_Simian Spirit Guide.jpg differ diff --git a/downloaded_images/sld_Sorin Markov_Sorin Markov.jpg b/downloaded_images/sld_Sorin Markov_Sorin Markov.jpg new file mode 100644 index 0000000..80a6375 Binary files /dev/null and b/downloaded_images/sld_Sorin Markov_Sorin Markov.jpg differ diff --git a/downloaded_images/sld_Tezzeret, Master of the Bridge_Tezzeret, Master of the Bridge.jpg b/downloaded_images/sld_Tezzeret, Master of the Bridge_Tezzeret, Master of the Bridge.jpg new file mode 100644 index 0000000..13039a2 Binary files /dev/null and b/downloaded_images/sld_Tezzeret, Master of the Bridge_Tezzeret, Master of the Bridge.jpg differ diff --git a/downloaded_images/sld_The Scorpion God_The Scorpion God.jpg b/downloaded_images/sld_The Scorpion God_The Scorpion God.jpg new file mode 100644 index 0000000..92d445a Binary files /dev/null and b/downloaded_images/sld_The Scorpion God_The Scorpion God.jpg differ diff --git a/downloaded_images/sld_Vilis, Broker of Blood_Vilis, Broker of Blood.jpg b/downloaded_images/sld_Vilis, Broker of Blood_Vilis, Broker of Blood.jpg new file mode 100644 index 0000000..f9c4be7 Binary files /dev/null and b/downloaded_images/sld_Vilis, Broker of Blood_Vilis, Broker of Blood.jpg differ diff --git a/downloaded_images/sld_Voracious Hydra_Voracious Hydra.jpg b/downloaded_images/sld_Voracious Hydra_Voracious Hydra.jpg new file mode 100644 index 0000000..9c0d44d Binary files /dev/null and b/downloaded_images/sld_Voracious Hydra_Voracious Hydra.jpg differ diff --git a/downloaded_images/Vraska, Golgari Queen_Vraska, Golgari Queen.jpg b/downloaded_images/sld_Vraska, Golgari Queen_Vraska, Golgari Queen.jpg similarity index 100% rename from downloaded_images/Vraska, Golgari Queen_Vraska, Golgari Queen.jpg rename to downloaded_images/sld_Vraska, Golgari Queen_Vraska, Golgari Queen.jpg diff --git a/downloaded_images/sld_Yargle, Glutton of Urborg_Yargle, Glutton of Urborg.jpg b/downloaded_images/sld_Yargle, Glutton of Urborg_Yargle, Glutton of Urborg.jpg new file mode 100644 index 0000000..780b7c1 Binary files /dev/null and b/downloaded_images/sld_Yargle, Glutton of Urborg_Yargle, Glutton of Urborg.jpg differ diff --git a/image_dl.py b/image_dl.py new file mode 100644 index 0000000..2aac789 --- /dev/null +++ b/image_dl.py @@ -0,0 +1,81 @@ +import requests +import pandas as pd +import os +import time + +# Function to fetch card details from Scryfall using the set code and collector number +def fetch_card_images_by_set_and_number(set_code, collector_number): + url = f"https://api.scryfall.com/cards/{set_code}/{collector_number}" + response = requests.get(url) + + if response.status_code == 200: + card_data = response.json() + images = [] + + # Handle single-sided or multi-sided cards + if 'image_uris' in card_data: + images.append((card_data['image_uris']['normal'], card_data['name'])) + if 'card_faces' in card_data: + for face in card_data['card_faces']: + if 'image_uris' in face: + images.append((face['image_uris']['normal'], face['name'])) + return images + else: + print(f"Error fetching card with set code {set_code} and collector number {collector_number}: {response.status_code}") + return None + +# Function to download and save an image +def download_image(image_url, save_path): + response = requests.get(image_url) + if response.status_code == 200: + with open(save_path, 'wb') as file: + file.write(response.content) + else: + print(f"Failed to download image from {image_url}") + +# Function to process the CSV and download images +def download_images_from_csv(csv_path, output_folder): + # Create output directory if it doesn't exist + if not os.path.exists(output_folder): + os.makedirs(output_folder) + + # Read the CSV file + df = pd.read_csv(csv_path) + + # Assuming the CSV has columns 'Card Name', 'Set Code', and 'Collector Number' + for index, row in df.iterrows(): + card_name = row['Card Name'] + set_code = row['Set Code'] + collector_number = row['Collector Number'] + + # Naming convention: set_code_card_name_face_name.jpg + image_base_name = f"{set_code}_{card_name.replace('/', '-').replace(':', '')}" + + print(f"Processing {card_name} from set {set_code} with collector number {collector_number}...") + + images = fetch_card_images_by_set_and_number(set_code, collector_number) + if images: + for image_url, face_name in images: + # Sanitize file name by removing invalid characters + image_file_name = f"{image_base_name}_{face_name.replace('/', '-').replace(':', '')}.jpg" + save_path = os.path.join(output_folder, image_file_name) + + # Skip downloading if the image already exists + if os.path.exists(save_path): + print(f"Image already exists for {card_name} ({face_name}), skipping download.") + continue + + download_image(image_url, save_path) + time.sleep(0.2) # Sleep to avoid hitting API rate limits + else: + print(f"No images found for {card_name} from set {set_code} with collector number {collector_number}") + +# Main execution +if __name__ == "__main__": + # Define the path to the input CSV and output folder + csv_path = 'cards.csv' # Replace with your CSV file path + output_folder = 'downloaded_images' + + # Start the download process + download_images_from_csv(csv_path, output_folder) + print("Download completed.") diff --git a/interactive_cards.py b/interactive_cards.py new file mode 100644 index 0000000..5b83e3a --- /dev/null +++ b/interactive_cards.py @@ -0,0 +1,39 @@ +import csv +import os + +# Function to append a card entry to the CSV file +def add_card_to_csv(csv_path, card_name, set_code, collector_number, quantity, foil): + file_exists = os.path.isfile(csv_path) + + with open(csv_path, mode='a', newline='') as file: + writer = csv.writer(file) + + # Write header if the file doesn't exist + if not file_exists: + writer.writerow(['Card Name', 'Set Code', 'Collector Number', 'Quantity', 'Foil']) + + # Append the card data + writer.writerow([card_name, set_code, collector_number, quantity, foil]) + + print(f"Added {quantity}x {card_name} from set {set_code} with collector number {collector_number} (Foil: {foil}) to {csv_path}.") + +# Function to get user input and add multiple cards interactively +def interactive_card_entry(csv_path): + while True: + # Get the card details from the user + card_name = input("Enter the card name (or type 'exit' to quit): ").strip() + if card_name.lower() == 'exit': + print("Exiting the program.") + break + + set_code = input("Enter the set code: ").strip() + collector_number = input("Enter the collector number: ").strip() + quantity = int(input("Enter the quantity: ").strip()) + foil = input("Is this card a foil? (yes/no): ").strip().lower() == 'yes' + + # Add the card to the CSV file + add_card_to_csv(csv_path, card_name, set_code, collector_number, quantity, foil) + +if __name__ == "__main__": + csv_path = input("Enter the path to the CSV file: ").strip() + interactive_card_entry(csv_path)