/
__init__.py
39 lines (31 loc) · 1.09 KB
/
__init__.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
35
36
37
38
39
import logging
from importlib import import_module
__version__ = '2.0.2'
def notify(message, title, config=None, **kwargs):
from .config import load_config
if config is None:
config = load_config()
ret = 0
for backend in config.get('backends', ['default']):
backend_config = config.get(backend, {})
backend_config.update(kwargs)
if 'backend' in backend_config:
backend = backend_config['backend']
try:
module = import_module('ntfy.backends.{}'.format(backend))
except ImportError:
ret = 1
logging.getLogger(__name__).error(
'failed to load backend {}'.format(backend),
exc_info=True)
continue
try:
module.notify(message=message, title=title, **backend_config)
except (SystemExit, KeyboardInterrupt):
raise
except Exception:
logging.getLogger(__name__).error(
'Failed to send notification using {}'.format(backend),
exc_info=True)
ret = 1
return ret