Files
CouchPotatoServer/couchpotato/core/notifications/prowl/main.py
T
2011-08-18 15:52:07 +02:00

44 lines
1.3 KiB
Python

from couchpotato.core.helpers.encoding import toUnicode
from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification
from httplib import HTTPSConnection
from urllib import urlencode
log = CPLog(__name__)
class Prowl(Notification):
listen_to = ['movie.downloaded', 'movie.snatched']
def notify(self, message = '', data = {}, type = None):
if self.dontNotify(type): return
http_handler = HTTPSConnection('api.prowlapp.com')
data = {
'apikey': self.conf('api_key'),
'application': self.default_title,
'event': 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 = urlencode(data)
)
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)
return False
else:
log.error('Prowl notification failed.')
return False