#!/usr/bin/env python3 import os.path from idb import Article, DocumentCreator from idb.util import image_url_to_filename, download_file, extract_images_from_markdown, read_file from argparse import ArgumentParser if __name__ == '__main__': parser = ArgumentParser() parser.add_argument('--ru-file', type=str, required=True, help='russian input file') parser.add_argument('--en-file', type=str, required=True, help='english input file') parser.add_argument('--output', type=str, required=True, help='output ODT file') args = parser.parse_args() orig = Article.from_markdown_file(args.ru_file, with_title=False) trans = Article.from_markdown_file(args.en_file, with_title=False) image_urls = extract_images_from_markdown(read_file(args.ru_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) if not os.path.exists(output_file): download_file(image_url, output_file) print(f'{image_name} saved') doc = DocumentCreator() doc.create(orig, trans, args.output)