Добавил возможность получения уведомления о старте обработчика в ТГ
This commit is contained in:
parent
d3432ebd25
commit
ee19e9be1e
|
@ -2,4 +2,5 @@ pydantic==1.10.7
|
|||
environs==9.5.0
|
||||
requests==2.30.0
|
||||
aiohttp~=3.8.4
|
||||
backoff~=2.2.1
|
||||
backoff~=2.2.1
|
||||
aiogram~=2.25.1
|
|
@ -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)
|
||||
|
|
19
src/tg_bot.py
Normal file
19
src/tg_bot.py
Normal file
|
@ -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)
|
Loading…
Reference in New Issue
Block a user