-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·40 lines (34 loc) · 1.09 KB
/
Copy pathmain.py
File metadata and controls
executable file
·40 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from summarizer import Summarizer
from tg_bot import TgBot
import os
from argparse import ArgumentParser
from pathlib import Path
from ruamel.yaml import YAML
# Читаем из аргументов путь к конфигу
arg_parser = ArgumentParser(
description="Справка"
)
arg_parser.add_argument(
"-c",
"--config",
default=Path(__file__).resolve().parent / "config.yaml",
help="Путь к конфигурационному YAML-файлу"
)
args = arg_parser.parse_args()
# Читаем конфиг
yaml = YAML()
yaml.preserve_quotes = True
with open(args.config, "r", encoding="utf-8") as file:
config = yaml.load(file)
# Создаём необходимые блоки
summarizer = Summarizer(config)
tg_bot = TgBot(
str(config["telegram_bot"]["token"]),
int(config["telegram_bot"]["recepient"])
)
summarizer.add_consumer(tg_bot.print)
# Формируем сводки
summarizer.summarize()
# Сохраняем конфиг (поменялись метки в чатах)
with open(args.config, "w", encoding="utf-8") as file:
yaml.dump(config, file)