Initial commit, win32 and darwin support only

This commit is contained in:
Kat Inskip 2023-09-08 17:07:20 -07:00 committed by Kat Inskip
commit 40df439299
Signed by: kat
GPG key ID: 465E64DECEA8CF0F
14 changed files with 527 additions and 0 deletions

31
downloader.py Normal file
View file

@ -0,0 +1,31 @@
import logging
import tempfile
import requests
from custom_print import kv_print
"""
Download files given a list of URLs
:param files: A list of URLs to download from
"""
def download_files(files: list) -> list:
logging.debug(f"download_posts() called with files=[{', '.join(files)}]")
# Keep a list of downloaded files
downloaded_files: list = []
# Download the images
for i, url in enumerate(files):
logging.debug(f"Downloading {url}")
# Get the image data
image = requests.get(url)
# Create a temporary file to store the image
image_file = tempfile.NamedTemporaryFile(delete=False)
logging.debug(f"Created temporary file {image_file.name}")
# Write the image data to the file
image_file.write(image.content)
# Close the file
image_file.close()
# Give the user data about the downloaded image
kv_print(f"Image {str(i+1)}", image_file.name, newline=True)
# Add the file to the list of downloaded files
downloaded_files.append(image_file.name)
return downloaded_files