diff --git a/couchpotato/core/notifications/pushover.py b/couchpotato/core/notifications/pushover.py index 6416bfe..ebce97c 100644 --- a/couchpotato/core/notifications/pushover.py +++ b/couchpotato/core/notifications/pushover.py @@ -1,6 +1,4 @@ -from httplib import HTTPSConnection - -from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode +from couchpotato.core.helpers.encoding import toUnicode from couchpotato.core.helpers.variable import getTitle, getIdentifier from couchpotato.core.logger import CPLog from couchpotato.core.notifications.base import Notification @@ -13,12 +11,11 @@ autoload = 'Pushover' class Pushover(Notification): + api_url = 'https://api.pushover.net' def notify(self, message = '', data = None, listener = None): if not data: data = {} - http_handler = HTTPSConnection("api.pushover.net:443") - api_data = { 'user': self.conf('user_key'), 'token': self.conf('api_token'), @@ -33,25 +30,17 @@ class Pushover(Notification): 'url_title': toUnicode('%s on IMDb' % getTitle(data)), }) - http_handler.request('POST', '/1/messages.json', - headers = {'Content-type': 'application/x-www-form-urlencoded'}, - body = tryUrlencode(api_data) - ) - - response = http_handler.getresponse() - request_status = response.status - - if request_status == 200: - log.info('Pushover notifications sent.') + try: + data = self.urlopen('%s/%s' % (self.api_url, '1/messages.json'), + headers = {'Content-type': 'application/x-www-form-urlencoded'}, + data = api_data) + log.info2('Pushover responded with: %s', data) return True - elif request_status == 401: - log.error('Pushover auth failed: %s', response.reason) - return False - else: - log.error('Pushover notification failed: %s', request_status) + except: return False + config = [{ 'name': 'pushover', 'groups': [