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.1 KiB

14 years ago
from couchpotato.core.helpers.encoding import toUnicode
from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification
import base64
import json
import traceback
14 years ago
log = CPLog(__name__)
class Notifo(Notification):
url = 'https://api.notifo.com/v1/send_notification'
def notify(self, message = '', data = None, listener = None):
if not data: data = {}
14 years ago
try:
14 years ago
params = {
'label': self.default_title,
14 years ago
'msg': toUnicode(message),
14 years ago
}
14 years ago
14 years ago
headers = {
'Authorization': "Basic %s" % base64.encodestring('%s:%s' % (self.conf('username'), self.conf('api_key')))[:-1]
}
14 years ago
14 years ago
handle = self.urlopen(self.url, params = params, headers = headers)
result = json.loads(handle)
14 years ago
if result['status'] != 'success' or result['response_message'] != 'OK':
raise Exception
except:
log.error('Notification failed: %s', traceback.format_exc())
14 years ago
return False
log.info('Notifo notification successful.')
return True