posttrack/notify.py

28 lines
726 B
Python

from notifypy import Notify
import telegram
import settings
def notify_local(title, message, icon=None):
notification = Notify()
notification.title = title
notification.message = message
if icon:
notification.icon = icon
notification.send()
def notify_telegram(title, message, icon=None, token=settings.TELEGRAM_TOKEN, recipients=settings.TELEGRAM_RECIPIENT_IDS):
bot = telegram.Bot(token=token)
for chat_id in recipients:
bot.sendMessage(chat_id=chat_id, text="%s: %s" % (title, message))
def notify(title, message, icon=None):
for handler in (notify_local, notify_telegram, ):
try:
handler(title, message, icon)
except:
pass