From c2453bb07000bc57bc0dbb42109f1dd9db779794 Mon Sep 17 00:00:00 2001 From: Travis La Marr Date: Tue, 1 Jan 2013 17:34:53 -0500 Subject: [PATCH] Added Windows Phone SuperToasty Notifier --- couchpotato/core/notifications/toasty/__init__.py | 32 +++++++++++++++++++++++ couchpotato/core/notifications/toasty/main.py | 30 +++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 couchpotato/core/notifications/toasty/__init__.py create mode 100644 couchpotato/core/notifications/toasty/main.py diff --git a/couchpotato/core/notifications/toasty/__init__.py b/couchpotato/core/notifications/toasty/__init__.py new file mode 100644 index 0000000..25d27ec --- /dev/null +++ b/couchpotato/core/notifications/toasty/__init__.py @@ -0,0 +1,32 @@ +from .main import Toasty + +def start(): + return Toasty() + +config = [{ + 'name': 'toasty', + 'groups': [ + { + 'tab': 'notifications', + 'name': 'toasty', + 'options': [ + { + 'name': 'enabled', + 'default': 0, + 'type': 'enabler', + }, + { + 'name': 'api_key', + 'label': 'Device ID', + }, + { + 'name': 'on_snatch', + 'default': 0, + 'type': 'bool', + 'advanced': True, + 'description': 'Also send message when movie is snatched.', + }, + ], + } + ], +}] diff --git a/couchpotato/core/notifications/toasty/main.py b/couchpotato/core/notifications/toasty/main.py new file mode 100644 index 0000000..34d338f --- /dev/null +++ b/couchpotato/core/notifications/toasty/main.py @@ -0,0 +1,30 @@ +from couchpotato.core.helpers.encoding import toUnicode +from couchpotato.core.logger import CPLog +from couchpotato.core.notifications.base import Notification +from httplib import HTTPConnection +from urllib import urlencode +import traceback + +log = CPLog(__name__) + +class Toasty(Notification): + + def notify(self, message = '', data = {}, listener = None): + if self.isDisabled(): return + + data = { + 'title': self.default_title, + 'text': toUnicode(message), + 'sender': toUnicode("CouchPotato"), + 'image': 'https://raw.github.com/RuudBurger/CouchPotatoServer/master/couchpotato/static/images/homescreen.png', + } + + try: + http_handler = HTTPConnection("api.supertoasty.com") + http_handler.request("GET", "/notify/"+self.conf('api_key')+"?"+urlencode(data)) + log.info('Toasty notifications sent.') + return True + except: + log.error('Toasty failed: %s', traceback.format_exc()) + + return False