diff --git a/couchpotato/core/notifications/pushover/__init__.py b/couchpotato/core/notifications/pushover/__init__.py new file mode 100644 index 00000000..949acc2b --- /dev/null +++ b/couchpotato/core/notifications/pushover/__init__.py @@ -0,0 +1,43 @@ +from .main import Pushover + +def start(): + return Pushover() + +config = [{ + 'name': 'pushover', + 'groups': [ + { + 'tab': 'notifications', + 'name': 'pushover', + 'label': 'Pushover', + 'options': [ + { + 'name': 'enabled', + 'default': 0, + 'type': 'enabler', + }, + { + 'name': 'user_key', + 'description': 'Register on pushover.net to get one.' + }, + { + 'name': 'app_token', + 'description': 'You can get one here.' + }, + { + 'name': 'priority', + 'default': 0, + 'type': 'dropdown', + 'values': [('Normal', 0), ('High', 1)], + }, + { + 'name': 'on_snatch', + 'default': 0, + 'type': 'bool', + 'advanced': True, + 'description': 'Also send message when movie is snatched.', + }, + ], + } + ], +}] diff --git a/couchpotato/core/notifications/pushover/main.py b/couchpotato/core/notifications/pushover/main.py new file mode 100644 index 00000000..6c406185 --- /dev/null +++ b/couchpotato/core/notifications/pushover/main.py @@ -0,0 +1,41 @@ +from couchpotato.core.helpers.encoding import toUnicode +from couchpotato.core.logger import CPLog +from couchpotato.core.notifications.base import Notification +from httplib import HTTPSConnection +from urllib import urlencode + +log = CPLog(__name__) + + +class Pushover(Notification): + + def notify(self, message = '', data = {}): + if self.isDisabled(): return + + http_handler = HTTPSConnection("api.pushover.net:443") + + data = { + 'user': self.conf('user_key'), + 'token': self.conf('app_token'), + 'message': toUnicode(message), + 'priority': self.conf('priority') + } + + http_handler.request('POST', + "/1/messages.json", + headers = {'Content-type': 'application/x-www-form-urlencoded'}, + body = urlencode(data) + ) + + response = http_handler.getresponse() + request_status = response.status + + if request_status == 200: + log.info('Pushover notifications sent.') + return True + elif request_status == 401: + log.error('Pushover auth failed: %s' % response.reason) + return False + else: + log.error('Pushover notification failed.') + return False