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.
88 lines
2.6 KiB
88 lines
2.6 KiB
13 years ago
|
from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode
|
||
12 years ago
|
from couchpotato.core.helpers.variable import getTitle
|
||
13 years ago
|
from couchpotato.core.logger import CPLog
|
||
|
from couchpotato.core.notifications.base import Notification
|
||
|
from httplib import HTTPSConnection
|
||
|
|
||
|
log = CPLog(__name__)
|
||
|
|
||
11 years ago
|
autoload = 'Pushover'
|
||
|
|
||
13 years ago
|
|
||
|
class Pushover(Notification):
|
||
|
|
||
13 years ago
|
app_token = 'YkxHMYDZp285L265L3IwH3LmzkTaCy'
|
||
|
|
||
12 years ago
|
def notify(self, message = '', data = None, listener = None):
|
||
|
if not data: data = {}
|
||
13 years ago
|
|
||
|
http_handler = HTTPSConnection("api.pushover.net:443")
|
||
|
|
||
12 years ago
|
api_data = {
|
||
13 years ago
|
'user': self.conf('user_key'),
|
||
13 years ago
|
'token': self.app_token,
|
||
13 years ago
|
'message': toUnicode(message),
|
||
12 years ago
|
'priority': self.conf('priority'),
|
||
13 years ago
|
}
|
||
|
|
||
11 years ago
|
if data and data.get('identifier'):
|
||
12 years ago
|
api_data.update({
|
||
11 years ago
|
'url': toUnicode('http://www.imdb.com/title/%s/' % data['identifier']),
|
||
|
'url_title': toUnicode('%s on IMDb' % getTitle(data)),
|
||
12 years ago
|
})
|
||
|
|
||
13 years ago
|
http_handler.request('POST',
|
||
11 years ago
|
"/1/messages.json",
|
||
|
headers = {'Content-type': 'application/x-www-form-urlencoded'},
|
||
|
body = tryUrlencode(api_data)
|
||
13 years ago
|
)
|
||
|
|
||
|
response = http_handler.getresponse()
|
||
|
request_status = response.status
|
||
|
|
||
|
if request_status == 200:
|
||
|
log.info('Pushover notifications sent.')
|
||
|
return True
|
||
|
elif request_status == 401:
|
||
13 years ago
|
log.error('Pushover auth failed: %s', response.reason)
|
||
13 years ago
|
return False
|
||
|
else:
|
||
|
log.error('Pushover notification failed.')
|
||
|
return False
|
||
11 years ago
|
|
||
|
|
||
|
config = [{
|
||
|
'name': 'pushover',
|
||
|
'groups': [
|
||
|
{
|
||
|
'tab': 'notifications',
|
||
|
'list': 'notification_providers',
|
||
|
'name': 'pushover',
|
||
|
'options': [
|
||
|
{
|
||
|
'name': 'enabled',
|
||
|
'default': 0,
|
||
|
'type': 'enabler',
|
||
|
},
|
||
|
{
|
||
|
'name': 'user_key',
|
||
|
'description': 'Register on pushover.net to get one.'
|
||
|
},
|
||
|
{
|
||
|
'name': 'priority',
|
||
|
'default': 0,
|
||
|
'type': 'dropdown',
|
||
|
'values': [('Normal', 0), ('High', 1)],
|
||
|
},
|
||
|
{
|
||
|
'name': 'on_snatch',
|
||
|
'default': 0,
|
||
|
'type': 'bool',
|
||
|
'advanced': True,
|
||
|
'description': 'Also send message when movie is snatched.',
|
||
|
},
|
||
|
],
|
||
|
}
|
||
|
],
|
||
|
}]
|