def download_image(image_url, img_id, img_directory): response = requests.get(image_url, allow_redirects=False, timeout=5) response.raise_for_status() chech_for_redirect(response) extension = img_id[-4:] img_name = sanitize_filename(os.path.join(get_unique_id(6), extension)) file_path = os.path.join(img_directory, img_name) with open(file_path, 'wb') as file: file.write(response.content) return file_path
def download_txt(download_url, book_title, book_directory): response = requests.get(download_url, allow_redirects=True, timeout=5) response.raise_for_status() chech_for_redirect(response) my_id = get_unique_id(6) book_name = sanitize_filename(f'{my_id} - {book_title}.txt') file_path = os.path.join(book_directory, book_name) with open(file_path, 'w') as file: file.write(response.text) return file_path
def _cleanup(filename_str): filename_str = sanitize_filename(filename_str, replacement_text="-", platform="universal") filename_str = filename_str.replace(ARG_DELIM, "-") return filename_str