-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathservice_notificator.py
34 lines (26 loc) · 1.09 KB
/
service_notificator.py
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
import asyncio
from datetime import datetime, timedelta
import json
import logging
from telegram import Bot
from helpers.translator import get_translation, TranslationKeys
from infrastructure.subscription_manager import get_subscriptions
async def send_notifications(bot):
subscriptions = get_subscriptions()
for subscription in subscriptions:
if subscription.enable_service_notifications == True:
try:
message = get_translation(subscription.culture, TranslationKeys.SERVICE_NOTIFICATION)
await bot.send_message(chat_id=subscription.chat_id, text=message)
except Exception as e:
logging.error(f"Failed to send message for chat_id {subscription.chat_id}: {str(e)}")
continue
async def main():
logging.basicConfig(level=logging.ERROR)
with open('/home/dgnaegi/altpapierBot/config_prod.json') as config_file:
config = json.load(config_file)
token = config["telegram"]["token"]
bot = Bot(token)
await send_notifications(bot)
if __name__ == '__main__':
asyncio.run(main())