latecomers/latecomers/main.py

49 lines
1.2 KiB
Python
Raw Permalink Normal View History

2022-08-25 13:12:38 +02:00
# -*- encoding: utf-8 -*-
import logging
import sys
import typing as T
2022-09-07 23:44:53 +02:00
from latecomers.retrieve import retrieve_from_inst, retrieve_from_fr24
from latecomers.parse import find_table, get_details, Details, parse_fr24
2022-08-25 13:12:38 +02:00
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)
2022-09-07 23:44:53 +02:00
body = retrieve_from_inst()
2022-08-25 13:12:38 +02:00
table = find_table(body)
2022-09-07 23:44:53 +02:00
fr24_data = retrieve_from_fr24()
aux_data = parse_fr24(fr24_data)
2022-08-25 13:12:38 +02:00
data: T.List[Details] = []
for row in table:
2022-09-07 23:44:53 +02:00
data.append(get_details(row, aux_data))
2022-08-25 13:12:38 +02:00
if not data:
2022-09-20 22:29:59 +02:00
out.send_no_data(config.to, config.cc)
2022-08-25 13:12:38 +02:00
2022-09-18 23:29:02 +02:00
excel = to_excel(data, config.store)
2022-09-20 22:29:59 +02:00
out.send_result(config.to, config.cc, excel)
2022-08-25 13:12:38 +02:00
def cli():
if len(sys.argv) < 2:
logger.error(f"Missing arguments: {sys.argv[0]} <config_path>")
sys.exit(4)
config_path = sys.argv[1]
config = Config(config_path)
main(config)