24 lines
990 B
Python
Executable File
24 lines
990 B
Python
Executable File
#!/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
|
|
|
|
|
|
if __name__ == '__main__':
|
|
name = 'cartier3'
|
|
orig_path = os.path.join(os.path.dirname(__file__), f'{name}_ru')
|
|
trans_path = os.path.join(os.path.dirname(__file__), f'{name}_en')
|
|
|
|
orig = Article.from_markdown_file(orig_path, with_title=False)
|
|
trans = Article.from_markdown_file(trans_path, with_title=False)
|
|
|
|
image_urls = extract_images_from_markdown(read_file(orig_path))
|
|
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, os.path.join(os.path.dirname(__file__), f'{name}.odt')) |