65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
# coding: utf-8
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import apprise
|
|
import pprint
|
|
|
|
from src.logs import Logger
|
|
|
|
|
|
class Notifications:
|
|
def __init__(self, config):
|
|
self.logger = Logger(
|
|
config["log"]["level"], config["log"]["path"]
|
|
)
|
|
self.config = config["notifications"]
|
|
self.apprise = apprise.Apprise()
|
|
self.allowedNotifyChannel = ["email", "discord", "matrix", "xmpp"]
|
|
self._notifyChannel = {
|
|
"email": self._addEmail(),
|
|
"discord": self._addDiscord(),
|
|
"xmpp": self._addXmpp(),
|
|
"matrix": self._addMatrix(),
|
|
}
|
|
self.setNotificationsChannel()
|
|
|
|
def setNotificationsChannel(self):
|
|
pprint.pprint(self)
|
|
for key, val in self.config.items():
|
|
if key not in self.allowedNotifyChannel:
|
|
self.logger.error(
|
|
"{} is not possible".format(self.allowedNotifyChannel)
|
|
)
|
|
else:
|
|
pprint.pprint(key)
|
|
pprint.pprint(self._notifyChannel)
|
|
self._notifyChannel[key]()
|
|
return True
|
|
|
|
def _addEmail(self):
|
|
self.logger.info("debug")
|
|
if self.config["email"]["secure"] is True:
|
|
mailto = "mailtos"
|
|
else:
|
|
mailto = "mailto"
|
|
self.apprise.add(
|
|
"{}://{}:{}@{}:{}?from={}&name=OVHTracker".format(
|
|
mailto,
|
|
self.config["email"]["user"],
|
|
self.config["email"]["password"],
|
|
self.config["email"]["host"],
|
|
self.config["email"]["port"],
|
|
self.config["email"]["from"]
|
|
)
|
|
)
|
|
|
|
def _addDiscord(self):
|
|
return True
|
|
|
|
def _addXmpp(self):
|
|
return True
|
|
|
|
def _addMatrix(self):
|
|
return True
|