Browse Source

Use own urlopen for pushover

fix #4839 #4814
pull/4942/head
Ruud 10 years ago
parent
commit
38363232a9
  1. 27
      couchpotato/core/notifications/pushover.py

27
couchpotato/core/notifications/pushover.py

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

Loading…
Cancel
Save