From ee19e9be1eb629aff0ef98ee687b30c8e7551c6b Mon Sep 17 00:00:00 2001 From: jsdio Date: Tue, 6 Jun 2023 14:16:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BE=20=D1=81=D1=82=D0=B0=D1=80=D1=82=D0=B5=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=87=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D0=A2=D0=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 ++- src/main.py | 9 ++++++++- src/tg_bot.py | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/tg_bot.py diff --git a/requirements.txt b/requirements.txt index bdeca5b..6cc690d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ pydantic==1.10.7 environs==9.5.0 requests==2.30.0 aiohttp~=3.8.4 -backoff~=2.2.1 \ No newline at end of file +backoff~=2.2.1 +aiogram~=2.25.1 \ No newline at end of file diff --git a/src/main.py b/src/main.py index 45b468a..8c103b0 100644 --- a/src/main.py +++ b/src/main.py @@ -6,8 +6,9 @@ from environs import load_dotenv from extractor import ApiExtractor from loader import EtlLoader -from settings import ApiConfig +from settings import ApiConfig, MiscSettings from state import JsonFileStorage, State +from tg_bot import TgBot load_dotenv() @@ -20,7 +21,13 @@ async def main(): api = ApiConfig() state = State(storage=storage) loader = EtlLoader() + tgbot = TgBot() + misc_settings = MiscSettings() logging.info('Обработчик готов к работе.') + + if misc_settings.use_notify: + await tgbot.send_notify('Обработчик запущен.') + while True: for iblock_id in api.iblocks: abitrs = await extractor.get_extract_data(iblock_id=int(iblock_id), state=state) diff --git a/src/tg_bot.py b/src/tg_bot.py new file mode 100644 index 0000000..f619370 --- /dev/null +++ b/src/tg_bot.py @@ -0,0 +1,19 @@ +import os + +from aiogram import Bot +from environs import load_dotenv + + +load_dotenv() + + +class TgBot: + + def __init__(self): + self.token = os.getenv('BOT_TOKEN') + self.chat_id = os.getenv('CHAT_ID') + self.bot = Bot(token=self.token) + + async def send_notify(self, text): + print(await self.bot.get_me()) + await self.bot.send_message(self.chat_id, text)