diff --git a/couchpotato/core/notifications/boxcar2/__init__.py b/couchpotato/core/notifications/boxcar2/__init__.py new file mode 100644 index 0000000..da7f99c --- /dev/null +++ b/couchpotato/core/notifications/boxcar2/__init__.py @@ -0,0 +1,34 @@ +from .main import Boxcar2 + + +def start(): + return Boxcar2() + +config = [{ + 'name': 'boxcar2', + 'groups': [ + { + 'tab': 'notifications', + 'list': 'notification_providers', + 'name': 'boxcar2', + 'options': [ + { + 'name': 'enabled', + 'default': 0, + 'type': 'enabler', + }, + { + 'name': 'token', + 'description': ('Your Boxcar access token.', 'Can be found in the app under settings') + }, + { + 'name': 'on_snatch', + 'default': 0, + 'type': 'bool', + 'advanced': True, + 'description': 'Also send message when movie is snatched.', + }, + ], + } + ], +}] diff --git a/couchpotato/core/notifications/boxcar2/main.py b/couchpotato/core/notifications/boxcar2/main.py new file mode 100644 index 0000000..6633ca7 --- /dev/null +++ b/couchpotato/core/notifications/boxcar2/main.py @@ -0,0 +1,39 @@ +from couchpotato.core.helpers.encoding import toUnicode +from couchpotato.core.logger import CPLog +from couchpotato.core.notifications.base import Notification + +log = CPLog(__name__) + + +class Boxcar2(Notification): + + url = 'https://new.boxcar.io/api/notifications' + + def notify(self, message = '', data = None, listener = None): + if not data: data = {} + + try: + message = message.strip() + + long_message = '' + if listener == 'test': + long_message = 'This is a test message' + elif data.get('identifier'): + long_message = 'More movie info on IMDB' % data['identifier'] + + data = { + 'user_credentials': self.conf('token'), + 'notification[title]': toUnicode(message), + 'notification[long_message]': toUnicode(long_message), + } + + self.urlopen(self.url, data = data) + except: + log.error('Make sure the token provided is for the correct device') + return False + + log.info('Boxcar notification successful.') + return True + + def isEnabled(self): + return super(Boxcar2, self).isEnabled() and self.conf('token')