From f66c125691c0a0317e7b381060743acebcfc5f75 Mon Sep 17 00:00:00 2001 From: Blallo Date: Thu, 25 Aug 2022 13:12:38 +0200 Subject: [PATCH] Add main entrypoint --- latecomers/main.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 latecomers/main.py diff --git a/latecomers/main.py b/latecomers/main.py new file mode 100644 index 0000000..a1919ad --- /dev/null +++ b/latecomers/main.py @@ -0,0 +1,46 @@ +# -*- encoding: utf-8 -*- +import logging +import sys +import typing as T + +from latecomers.retrieve import retrieve +from latecomers.parse import find_table, get_details, Details +from latecomers.serializer import to_excel +from latecomers.notifier import Notifier +from latecomers.config import Config + + +logging.basicConfig( + level=logging.INFO, + format="[%(asctime)s] %(levelname)s - %(message)s", + datefmt="%H:%M:%S", +) +logger = logging.getLogger(__name__) + + +def main(config: Config): + """ + The main cli entrypoint. + """ + out = Notifier(**config.smtp) + body = retrieve() + table = find_table(body) + data: T.List[Details] = [] + for row in table: + data.append(get_details(row)) + + if not data: + out.send_no_data(config.to) + + excel = to_excel(data) + out.send_result(config.to, excel) + + +def cli(): + if len(sys.argv) < 2: + logger.error(f"Missing arguments: {sys.argv[0]} ") + sys.exit(4) + + config_path = sys.argv[1] + config = Config(config_path) + main(config)