Initial commit

This commit is contained in:
moanos [he/him] 2023-09-13 12:05:44 +02:00
commit 335b1ab456
2 changed files with 39 additions and 0 deletions

36
main.py Normal file
View File

@ -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('<head>\n')
file.writelines('<meta charset="UTF-8">\n')
if css:
file.writelines(f'<link rel="stylesheet" href="{css}">\n')
file.writelines('</head>\n')
file.writelines('<body>\n')
file.write(books_as_html)
file.writelines('</body>\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()

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
pandas
odfpy
requests