culture-creative-cc-licences/get_logos.py
2023-06-18 12:10:02 -04:00

47 lines
1.6 KiB
Python

import requests
import os
def download_file(url, directory):
# Create the directory if it doesn't exist
os.makedirs(directory, exist_ok=True)
# Extract the filename from the URL
filename = url.split("/")[-1]
# Set the output file path
output_path = os.path.join(directory, filename)
try:
# Send a GET request to the URL
response = requests.get(url)
response.raise_for_status() # Raise an exception if the request was unsuccessful
# Save the response content to a file
with open(output_path, "wb") as file:
file.write(response.content)
print("File downloaded successfully!")
print("Saved as:", output_path)
except requests.exceptions.RequestException as e:
print("Error occurred during file download:", e)
# URL of the file to download
file_urls = [
"https://mirrors.creativecommons.org/presskit/buttons/88x31/png/by.png",
"https://mirrors.creativecommons.org/presskit/buttons/88x31/png/by-sa.png",
"https://mirrors.creativecommons.org/presskit/buttons/88x31/png/by-nc.png",
"https://mirrors.creativecommons.org/presskit/buttons/88x31/png/by-nc-sa.png",
"https://mirrors.creativecommons.org/presskit/buttons/88x31/png/by-nc-nd.png",
"https://mirrors.creativecommons.org/presskit/buttons/88x31/png/by-nd.png",
"https://mirrors.creativecommons.org/presskit/buttons/88x31/png/cc-zero.png",
"https://mirrors.creativecommons.org/presskit/buttons/88x31/png/publicdomain.png"
]
# Directory to save the file
save_directory = "logos"
# Call the download_file function
for file_url in file_urls:
download_file(file_url, save_directory)