Skip to content

Commit

Permalink
fixed exporting to markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaya-Sem committed Jul 14, 2024
1 parent 2b41af8 commit cf36275
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/export_commands.py
Original file line number Diff line number Diff line change
@@ -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}")

Expand All @@ -45,3 +48,7 @@ def generate_markdown_checklist(collection):

def pad_string(s, width):
return s + ' ' * (width - len(s))


if __name__ == "__main__":
pass
Binary file added src/test2.pdf
Binary file not shown.

0 comments on commit cf36275

Please sign in to comment.