2014-03-10 05:18:05 +00:00
|
|
|
import sickbeard
|
2017-10-17 15:43:28 +00:00
|
|
|
from sickbeard.notifiers.generic import Notifier
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
from lib.pynma import pynma
|
|
|
|
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
class NMANotifier(Notifier):
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
def _notify(self, title, body, nma_api=None, nma_priority=None, **kwargs):
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
nma_api = self._choose(nma_api, sickbeard.NMA_API)
|
|
|
|
nma_priority = self._choose(nma_priority, sickbeard.NMA_PRIORITY)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
batch = False
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
p = pynma.PyNMA()
|
|
|
|
keys = nma_api.split(',')
|
|
|
|
p.addkey(keys)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
if 1 < len(keys):
|
|
|
|
batch = True
|
|
|
|
|
|
|
|
self._log_debug('Sending notice with priority=%s, batch=%s' % (nma_priority, batch))
|
|
|
|
response = p.push('SickGear', title, body, priority=nma_priority, batch_mode=batch)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
result = False
|
|
|
|
try:
|
|
|
|
if u'200' != response[nma_api][u'code']:
|
|
|
|
self._log_error('Notification failed')
|
|
|
|
else:
|
|
|
|
result = True
|
|
|
|
except (StandardError, Exception):
|
|
|
|
pass
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
return result
|
2014-03-25 05:57:24 +00:00
|
|
|
|
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
notifier = NMANotifier
|