From 335b1ab4564f5721302d9b6f2e00869f6a2a4079 Mon Sep 17 00:00:00 2001 From: moanos Date: Wed, 13 Sep 2023 12:05:44 +0200 Subject: [PATCH] Initial commit --- main.py | 36 ++++++++++++++++++++++++++++++++++++ requirements.txt | 3 +++ 2 files changed, 39 insertions(+) create mode 100644 main.py create mode 100644 requirements.txt diff --git a/main.py b/main.py new file mode 100644 index 0000000..fddc94a --- /dev/null +++ b/main.py @@ -0,0 +1,36 @@ +import pandas as pd +import argparse +import requests + + +def write_html(df, filename, css=None): + books_as_html = df[["Titel ", "Autor*in", "Sprache", "Kategorie"]].to_html() + with open(filename, "w", encoding="utf-8") as file: + file.writelines('\n') + file.writelines('\n') + if css: + file.writelines(f'\n') + file.writelines('\n') + file.writelines('\n') + file.write(books_as_html) + file.writelines('\n') + + +def cli(): + parser = argparse.ArgumentParser(description='Convert an odt document to a book') + parser.add_argument('-i', '--input-file', help="The input file (odf format)") + parser.add_argument('-o', '--output', help="Filename where to export the html table to") + parser.add_argument('--healthcheck', help="[Optional] Healthcheck URL") + parser.add_argument('--css', help="[Optional] relative css file location") + args = parser.parse_args() + + book_df = pd.read_excel(args.input, engine="odf") + + write_html(book_df, args.output, args.css) + + if args.healthcheck: + requests.post(args.healthcheck, data=f"num_books={len(book_df)}") + + +if __name__ == "__main__": + cli() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8f7ff82 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pandas +odfpy +requests \ No newline at end of file