From cf36275cf1f2e94ab99d2aef630b81b5631e2901 Mon Sep 17 00:00:00 2001 From: Kaya-Sem Date: Sun, 14 Jul 2024 16:48:22 +0200 Subject: [PATCH] fixed exporting to markdown --- src/export_commands.py | 29 ++++++++++++++++++----------- src/test2.pdf | Bin 0 -> 366 bytes 2 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 src/test2.pdf diff --git a/src/export_commands.py b/src/export_commands.py index 6e5d301..fba9e8e 100644 --- a/src/export_commands.py +++ b/src/export_commands.py @@ -1,27 +1,30 @@ import click + from database import get_collection @click.command() @click.argument('collection_id', type=int) @click.argument('output_file', type=click.Path(writable=True)) -@click.option('--markdown', is_flag=True, help='Creates a markdown checklist instead of a PDF') -def checklist(collection_id, output_file): +@click.option('--pdf', is_flag=True, help='Creates a PDF checklist instead of a markdown') +def checklist(collection_id, output_file, pdf): """ - Export a collection of items as a markdown checklist. + Export a collection of items as a markdown checklist or PDF. COLLECTION_ID: The ID of the collection to export. - OUTPUT_FILE: The file to write the markdown checklist to. - --markdown: Creates a markdown file instead of PDF + OUTPUT_FILE: The file to write the checklist to. + --pdf: Creates a markdown file instead of PDF. """ try: collection = get_collection(collection_id) - markdown_content = generate_markdown_checklist(collection) - - with open(output_file, 'w') as file: - file.write(markdown_content) - - click.echo(f"Collection {collection_id} exported to {output_file} successfully.") + if not pdf: + markdown_content = generate_markdown_checklist(collection) + with open(output_file, 'w') as file: + file.write(markdown_content) + click.echo(f"Collection {collection_id} exported to {output_file} as markdown successfully.") + else: + # generate_pdf_checklist(collection, output_file) + click.echo(f"Collection {collection_id} exported to {output_file} as PDF successfully.") except Exception as e: click.echo(f"An error occurred: {e}") @@ -45,3 +48,7 @@ def generate_markdown_checklist(collection): def pad_string(s, width): return s + ' ' * (width - len(s)) + + +if __name__ == "__main__": + pass diff --git a/src/test2.pdf b/src/test2.pdf new file mode 100644 index 0000000000000000000000000000000000000000..a787c88b86b79a22f860f3d3ea38b23398fb2216 GIT binary patch literal 366 zcmZXQF;2uV5Jh{R;!A0=5|LIB()Q3GvD@rYtUwfAGB}ndwq=i%ThMa=?!bAt09U}v zCIw-dnZobS8&|l`&LpOeoO&G34Fd^wmbJsz`^Wd^n^IL(;m{KcMWq@%;TbpHz2;Qj zbzNyK7FECa#*dCVj8=LK=eX5`?z}TP{%59$x(x_91||qOnW;O=Oecy42cOw5_MyIR z66xe!S?G%A#9q{yD9qvyJ;gysN`m9>{5PrI>S*ZdqP^cBYO&7D61RECT<$$?tq|Jv ZdI4vasM(rc(3SI1K9)k^andD2{Qy;XXIB6K literal 0 HcmV?d00001