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)