From 07645e33d04ff9917aa43e589adebd43ef557210 Mon Sep 17 00:00:00 2001 From: 0ceanSlim Date: Mon, 13 Nov 2023 11:34:47 -0500 Subject: [PATCH] first commit --- .gitignore | 1 + README.md | 33 +++++++++++++++++++++++++++++ mian.py | 48 +++++++++++++++++++++++++++++++++++++++++++ src/lorcana_1.1.py | 25 ++++++++++++++++++++++ src/lorcana_1.py | 25 ++++++++++++++++++++++ src/lorcana_2.py | 27 ++++++++++++++++++++++++ src/lorcana_promos.py | 25 ++++++++++++++++++++++ 7 files changed, 184 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 mian.py create mode 100644 src/lorcana_1.1.py create mode 100644 src/lorcana_1.py create mode 100644 src/lorcana_2.py create mode 100644 src/lorcana_promos.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b322272 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/images \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0a2ac1f --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# Disney's Lorcana Python Tools + +## Prerequisites + +Before you begin, ensure you have met the following requirements: +- Python installed + +You can download the latest version of Python from python.org. +During installation, make sure to add Python to your system's PATH. + +## Getting Started + +To get started with the project, follow these steps: + +Clone the repository to your local machine: + +```bash +git clone https://github.com/0ceanslim/lorcana.git +``` +Navigate to the project directory: + +```bash +cd lorcana +``` + +# Usage + +- The only funtionality at the moment is grabbing the pngs for all the cards in the game and saving them into a local folder. You can do that just by running the main script in the root of this directory + +```bash +python main.py +``` +This currently runs all the scripts in the src folder and grabs all current card images for the game. \ No newline at end of file diff --git a/mian.py b/mian.py new file mode 100644 index 0000000..2c9121e --- /dev/null +++ b/mian.py @@ -0,0 +1,48 @@ +import os +import subprocess +import sys + +def check_python_installation(): + try: + python_version = subprocess.check_output( + ["python", "--version"], stderr=subprocess.STDOUT, universal_newlines=True + ) + print(f"{python_version}") + return True + except FileNotFoundError: + return False + +def install_python(): + print("Python is not installed. Please download and install it from:") + print("https://www.python.org/downloads/") + input("Press Enter to continue after installing Python...") + sys.exit(1) + +def run_scripts_in_folder(folder_path): + if not check_python_installation(): + install_python() + + # Get a list of all files in the folder + script_files = [f for f in os.listdir(folder_path) if f.endswith('.py')] + + if not script_files: + print(f"No Python scripts found in {folder_path}") + return + + for script_file in script_files: + script_path = os.path.join(folder_path, script_file) + + # Run the script using subprocess + try: + subprocess.run(['python', script_path], check=True) + print(f"Script {script_file} executed successfully.") + except subprocess.CalledProcessError as e: + print(f"Error executing script {script_file}: {e}") + +if __name__ == "__main__": + # Specify the folder containing the scripts + scripts_folder = "src" + + run_scripts_in_folder(scripts_folder) + + print("Done.") diff --git a/src/lorcana_1.1.py b/src/lorcana_1.1.py new file mode 100644 index 0000000..11cd277 --- /dev/null +++ b/src/lorcana_1.1.py @@ -0,0 +1,25 @@ +import os +import requests + +def download_images(base_url, set_name, num_images, local_folder): + # Ensure the local folder exists + os.makedirs(local_folder, exist_ok=True) + + for i in range(205, num_images + 1): + image_url = f"{base_url}/{set_name}/{i}.png" #might have to add the set tag here + response = requests.get(image_url) + + if response.status_code == 200: + with open(os.path.join(local_folder, f"{i}.png"), 'wb') as file: + file.write(response.content) + print(f"Downloaded {i}.png") + else: + print(f"Failed to download {i}.png - Status code: {response.status_code}") + +if __name__ == "__main__": + base_url = "https://www.lorcanawiz.com/images" #/thefirstchapter/TFC-205.png + set_name = "thefirstchapter" + num_images = 216 + local_folder = f"images/{set_name}/" + + download_images(base_url, set_name, num_images, local_folder) diff --git a/src/lorcana_1.py b/src/lorcana_1.py new file mode 100644 index 0000000..ebf58bc --- /dev/null +++ b/src/lorcana_1.py @@ -0,0 +1,25 @@ +import os +import requests + +def download_images(base_url, set_name, num_images, local_folder): + # Ensure the local folder exists + os.makedirs(local_folder, exist_ok=True) + + for i in range(1, num_images + 1): + image_url = f"{base_url}/{set_name}/TFC-{i}.png" #might have to add the set tag here + response = requests.get(image_url) + + if response.status_code == 200: + with open(os.path.join(local_folder, f"{i}.png"), 'wb') as file: + file.write(response.content) + print(f"Downloaded {i}.png") + else: + print(f"Failed to download {i}.png - Status code: {response.status_code}") + +if __name__ == "__main__": + base_url = "https://www.lorcanawiz.com/images" #/thefirstchapter/TFC-205.png + set_name = "thefirstchapter" + num_images = 204 + local_folder = f"images/{set_name}/" + + download_images(base_url, set_name, num_images, local_folder) diff --git a/src/lorcana_2.py b/src/lorcana_2.py new file mode 100644 index 0000000..dbd6024 --- /dev/null +++ b/src/lorcana_2.py @@ -0,0 +1,27 @@ +import os +import requests + +def download_images(base_url, set_name, num_images, local_folder): + # Ensure the local folder exists + os.makedirs(local_folder, exist_ok=True) + + for i in range(1, num_images + 1): + image_url = f"{base_url}/{set_name}/{i}.png" + response = requests.get(image_url) + + if response.status_code == 200 and 'image' in response.headers.get('Content-Type', ''): + with open(os.path.join(local_folder, f"{i}.png"), 'wb') as file: + file.write(response.content) + print(f"Downloaded {i}.png") + elif response.status_code == 404: + print(f"Image {i}.png not found - Status code: {response.status_code}") + else: + print(f"Failed to download {i}.png - Status code: {response.status_code}") + +if __name__ == "__main__": + base_url = "https://www.lorcanawiz.com/images" + set_name = "riseofthefloodborn" + num_images = 250 + local_folder = f"images/{set_name}/" + + download_images(base_url, set_name, num_images, local_folder) diff --git a/src/lorcana_promos.py b/src/lorcana_promos.py new file mode 100644 index 0000000..b549ddd --- /dev/null +++ b/src/lorcana_promos.py @@ -0,0 +1,25 @@ +import os +import requests + +def download_images(base_url, set_name, num_images, local_folder): + # Ensure the local folder exists + os.makedirs(local_folder, exist_ok=True) + + for i in range(1, num_images + 1): + image_url = f"{base_url}/{set_name}/{i}.png" #might have to add the set tag here + response = requests.get(image_url) + + if response.status_code == 200 and 'image' in response.headers.get('Content-Type', ''): + with open(os.path.join(local_folder, f"{i}.png"), 'wb') as file: + file.write(response.content) + print(f"Downloaded {i}.png") + else: + print(f"Failed to download {i}.png - Status code: {response.status_code}") + +if __name__ == "__main__": + base_url = "https://www.lorcanawiz.com/images" #/thefirstchapter/205.png + set_name = "promos" + num_images = 24 + local_folder = f"images/{set_name}/" + + download_images(base_url, set_name, num_images, local_folder)