From 85d6e42be9e7811c0b7c8c62991b6b183e77d548 Mon Sep 17 00:00:00 2001 From: 0ceanSlim Date: Tue, 14 Nov 2023 11:30:28 -0500 Subject: [PATCH] name folder set names specefied by --- saveImages.py | 16 ++++++++++++---- getData.py => scrapeLorcania.py | 0 sets.json | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) rename getData.py => scrapeLorcania.py (100%) create mode 100644 sets.json diff --git a/saveImages.py b/saveImages.py index e0c5f6f..5c95748 100644 --- a/saveImages.py +++ b/saveImages.py @@ -2,11 +2,16 @@ import os import pandas as pd import requests import re +import json # Function to clean filename by removing problematic characters def clean_filename(filename): return re.sub(r'[\\/*?:"<>|]', '', filename) +# Load set names from JSON file +with open('sets.json', 'r') as file: + set_names_mapping = json.load(file) + # Read the CSV file data = pd.read_csv('data.csv') @@ -17,19 +22,22 @@ os.makedirs(images_folder, exist_ok=True) # Iterate through the rows for index, row in data.iterrows(): card_set_id = row['card_set_id'] - card_id = row['id'] + set_id = row['number'] name = row['name'] image_url = row['image'] - # Create a folder for the card_set_id if it doesn't exist - card_set_folder = os.path.join(images_folder, str(card_set_id)) + # Get set name from mapping + set_name = set_names_mapping.get(str(card_set_id), f"set_{card_set_id}") + + # Create a folder for the set_name if it doesn't exist + card_set_folder = os.path.join(images_folder, set_name) os.makedirs(card_set_folder, exist_ok=True) # Get the image response = requests.get(image_url) if response.status_code == 200: # Clean the filename - image_filename = clean_filename(f"{card_id} - {name}.webp") # Adjust the extension if needed + image_filename = clean_filename(f"{set_id} - {name}.webp") # Adjust the extension if needed image_path = os.path.join(card_set_folder, image_filename) with open(image_path, 'wb') as f: f.write(response.content) diff --git a/getData.py b/scrapeLorcania.py similarity index 100% rename from getData.py rename to scrapeLorcania.py diff --git a/sets.json b/sets.json new file mode 100644 index 0000000..1209b66 --- /dev/null +++ b/sets.json @@ -0,0 +1,5 @@ +{ + "1": "0 - Promo", + "2": "1 - The First Chapter", + "3": "2 - Rise of the Floodborn" +}