mirror of
https://github.com/JonasunderscoreJones/turbo-octo-potato.git
synced 2025-10-24 10:39:19 +02:00
Refactor to obey to pep-8
This commit is contained in:
parent
d953c469cf
commit
9f3692c217
1 changed files with 9 additions and 8 deletions
|
|
@ -1,22 +1,23 @@
|
|||
'''A script to download all the banners from the CDN and save them to a local directory.'''
|
||||
import json
|
||||
import os
|
||||
import requests
|
||||
|
||||
# Define the URL pattern for downloading images
|
||||
base_url = "https://cdn.jonasjones.dev/project-banners"
|
||||
BASE_URL = "https://cdn.jonasjones.dev/project-banners"
|
||||
|
||||
# Define the path to the JSON file
|
||||
json_file_path = "/home/jonas_jones/GitHub/jonasjones.dev/src/routes/projects/projects.json"
|
||||
JSON_FILE_PATH = "/home/jonas_jones/GitHub/jonasjones.dev/src/routes/projects/projects.json"
|
||||
|
||||
# Define the directory where you want to save the downloaded images
|
||||
download_directory = os.path.expanduser("~/Downloads/uwu/")
|
||||
DOWNLOAD_DIR = os.path.expanduser("~/Downloads/uwu/")
|
||||
|
||||
# Create the download directory if it doesn't exist
|
||||
os.makedirs(download_directory, exist_ok=True)
|
||||
os.makedirs(DOWNLOAD_DIR, exist_ok=True)
|
||||
|
||||
try:
|
||||
# Open and parse the JSON file
|
||||
with open(json_file_path, "r") as json_file:
|
||||
with open(JSON_FILE_PATH, "r") as json_file:
|
||||
data = json.load(json_file)
|
||||
|
||||
# Iterate through the list of objects in the JSON file
|
||||
|
|
@ -25,7 +26,7 @@ try:
|
|||
if "backgroud" in item:
|
||||
background_value = item["backgroud"]
|
||||
# Construct the full URL for the image
|
||||
image_url = f"{base_url}{background_value}"
|
||||
image_url = f"{BASE_URL}{background_value}"
|
||||
|
||||
# Download the image
|
||||
response = requests.get(image_url)
|
||||
|
|
@ -33,7 +34,7 @@ try:
|
|||
# Get the filename from the URL
|
||||
filename = os.path.basename(image_url)
|
||||
# Save the image to the download directory
|
||||
with open(os.path.join(download_directory, filename), "wb") as image_file:
|
||||
with open(os.path.join(DOWNLOAD_DIR, filename), "wb") as image_file:
|
||||
image_file.write(response.content)
|
||||
print(f"Downloaded: {filename}")
|
||||
else:
|
||||
|
|
@ -42,6 +43,6 @@ try:
|
|||
print(f"Doesn't contain background: {item}")
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"JSON file not found: {json_file_path}")
|
||||
print(f"JSON file not found: {JSON_FILE_PATH}")
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue