idb_utils/tzo_images.py
2025-05-17 04:28:55 +03:00

26 lines
974 B
Python
Executable File

#!/usr/bin/env python3
import os.path
from argparse import ArgumentParser
from idb import tzo_urls, after_tzo_urls
from idb.util import read_file, name_from_url, image_url_to_filename, download_file, extract_images_from_markdown
from dotenv import load_dotenv
load_dotenv()
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--after', action='store_true')
args = parser.parse_args()
urls = tzo_urls if not args.after else after_tzo_urls
for url in urls:
name = name_from_url(url)
markdown_file = os.path.join(os.path.dirname(__file__), 'tzo', f'{name}-ru.txt')
image_urls = extract_images_from_markdown(read_file(markdown_file))
for image_url in image_urls:
image_name = image_url_to_filename(image_url)
output_file = os.path.join(os.path.dirname(__file__), 'images', image_name)
download_file(image_url, output_file)
print(f'{image_name} saved')