Created
September 24, 2024 23:18
-
-
Save hyperdefined/d9d2e37aa5d4b7e8de3126d6d978a07a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mostly made with ai because I am lazy | |
import os | |
import requests | |
from urllib.parse import urlparse | |
json_url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s' | |
output_folder = 'output' | |
if not os.path.exists(output_folder): | |
os.makedirs(output_folder) | |
response = requests.get(json_url) | |
data = response.json() | |
image_data = data.get("data", {}) | |
for key, value in data['data'].items(): | |
image_url = value.get('dhd') | |
if image_url: | |
parsed_url = urlparse(image_url) | |
file_extension = os.path.splitext(parsed_url.path)[1] | |
file_name = f"{key}{file_extension}" | |
image_response = requests.get(image_url) | |
if image_response.status_code == 200: | |
file_path = os.path.join(output_folder, file_name) | |
with open(file_path, 'wb') as image_file: | |
image_file.write(image_response.content) | |
print(f"Downloaded: {file_name}") | |
else: | |
print(f"Failed to download: {image_url}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment