From c38d87379a4ea52581db4088e064ea91639a39d2 Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 27 Apr 2023 13:53:41 +0200 Subject: [PATCH] Added --convert argument --- main.py | 21 +++++++++++++++++---- requirements.txt | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 537ad76..b3b9440 100644 --- a/main.py +++ b/main.py @@ -1,18 +1,24 @@ +from argparse import ArgumentParser from datetime import datetime from locale import LC_ALL, setlocale from os import makedirs, path from pathlib import Path from typing import Any +from docx2pdf import convert from docxtpl import DocxTemplate +parser = ArgumentParser(description="Ping script") +parser.add_argument( + "--convert", + dest="convert_output", + action="store_true", + help="convert output .docx files to .pdf", +) + from modules.utils import data_read, json_read -def local_if_available(data: dict, data_local: dict, *args: str) -> Any: - return - - def main(): for lang in config["languages"]: # data = json_read(Path("data", "default.json")) @@ -151,6 +157,7 @@ def main(): if __name__ == "__main__": + args = parser.parse_args() config = json_read(Path("config.json")) makedirs(Path(".cache"), exist_ok=True) if not path.exists(Path(".cache", "location")): @@ -167,3 +174,9 @@ if __name__ == "__main__": cached_location if signature_location == "" else signature_location ) main() + if args.convert_output: + print( + f"Converting everything to PDF...", + flush=True, + ) + convert(Path("output").absolute()) diff --git a/requirements.txt b/requirements.txt index 15dbf20..8864bac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ +argparse==1.4.0 +docx2pdf==0.1.8 docxtpl==0.16.6 \ No newline at end of file