You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode
14 years ago
from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification
from httplib import HTTPSConnection
log = CPLog(__name__)
class Prowl(Notification):
def notify(self, message = '', data = {}, listener = None):
if self.isDisabled(): return
14 years ago
http_handler = HTTPSConnection('api.prowlapp.com')
data = {
'apikey': self.conf('api_key'),
'application': self.default_title,
'description': toUnicode(message),
'priority': self.conf('priority'),
}
http_handler.request('POST',
'/publicapi/add',
headers = {'Content-type': 'application/x-www-form-urlencoded'},
body = tryUrlencode(data)
14 years ago
)
response = http_handler.getresponse()
request_status = response.status
if request_status == 200:
log.info('Prowl notifications sent.')
return True
elif request_status == 401:
log.error('Prowl auth failed: %s', response.reason)
14 years ago
return False
else:
log.error('Prowl notification failed.')
return False