From a3af784c18024667fc93ac205b0d8713a6c8df60 Mon Sep 17 00:00:00 2001 From: Steven Lu Date: Tue, 6 Jan 2015 18:33:06 -0500 Subject: [PATCH] Adding the ability to receive notifications through Webhooks --- couchpotato/core/notifications/webhook.py | 66 +++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 couchpotato/core/notifications/webhook.py diff --git a/couchpotato/core/notifications/webhook.py b/couchpotato/core/notifications/webhook.py new file mode 100644 index 00000000..d970bb53 --- /dev/null +++ b/couchpotato/core/notifications/webhook.py @@ -0,0 +1,66 @@ +from couchpotato.core.helpers.encoding import toUnicode +from couchpotato.core.helpers.variable import getIdentifier +from couchpotato.core.logger import CPLog +from couchpotato.core.notifications.base import Notification + +log = CPLog(__name__) + +autoload = 'Webhook' + +class Webhook(Notification): + + + def notify(self, message = '', data = None, listener = None): + if not data: data = {} + + post_data = { + 'message': toUnicode(message) + } + + if getIdentifier(data): + post_data.update({ + 'imdb_id': getIdentifier(data) + }) + + headers = { + 'Content-type': 'application/x-www-form-urlencoded' + } + + try: + self.urlopen(self.conf('url'), headers = headers, data = post_data, show_error = False) + return True + except: + log.error('Webhook notification failed: %s', traceback.format_exc()) + + return False + + +config = [{ + 'name': 'webhook', + 'groups': [ + { + 'tab': 'notifications', + 'list': 'notification_providers', + 'name': 'webhook', + 'label': 'Webhook', + 'options': [ + { + 'name': 'enabled', + 'default': 0, + 'type': 'enabler', + }, + { + 'name': 'url', + 'description': 'The URL to send notification data to when ' + }, + { + 'name': 'on_snatch', + 'default': 0, + 'type': 'bool', + 'advanced': True, + 'description': 'Also send message when movie is snatched.', + } + ] + } + ] +}]