Add main entrypoint
This commit is contained in:
parent
f50ba1050a
commit
f66c125691
46
latecomers/main.py
Normal file
46
latecomers/main.py
Normal file
|
@ -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]} <config_path>")
|
||||||
|
sys.exit(4)
|
||||||
|
|
||||||
|
config_path = sys.argv[1]
|
||||||
|
config = Config(config_path)
|
||||||
|
main(config)
|
Loading…
Reference in New Issue
Block a user