2014-03-10 05:18:05 +00:00
|
|
|
# Author: Maciej Olesinski (https://github.com/molesinski/)
|
|
|
|
# Based on prowl.py by Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# This file is part of SickGear.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is free software: you can redistribute it and/or modify
|
2014-03-10 05:18:05 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is distributed in the hope that it will be useful,
|
2014-03-10 05:18:05 +00:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2014-11-12 16:43:14 +00:00
|
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-09-07 00:51:44 +00:00
|
|
|
import socket
|
2014-03-10 05:18:05 +00:00
|
|
|
from ssl import SSLError
|
2017-10-17 15:43:28 +00:00
|
|
|
from urllib import urlencode
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
import sickbeard
|
2017-10-17 15:43:28 +00:00
|
|
|
from sickbeard.notifiers.generic import Notifier
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
from lib.six import moves
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
class PushalotNotifier(Notifier):
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
def _notify(self, title, body, pushalot_auth_token=None, **kwargs):
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
pushalot_auth_token = self._choose(pushalot_auth_token, sickbeard.PUSHALOT_AUTHORIZATIONTOKEN)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2017-10-17 15:43:28 +00:00
|
|
|
self._log_debug(u'Title: %s, Message: %s, API: %s' % (title, body, pushalot_auth_token))
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2015-08-16 03:23:56 +00:00
|
|
|
http_handler = moves.http_client.HTTPSConnection('pushalot.com')
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
try:
|
2017-10-17 15:43:28 +00:00
|
|
|
http_handler.request('POST', '/api/sendmessage',
|
|
|
|
body=urlencode(dict(Title=title.encode('utf-8'), Body=body.encode('utf-8'),
|
|
|
|
AuthorizationToken=pushalot_auth_token)),
|
|
|
|
headers={'Content-type': 'application/x-www-form-urlencoded'})
|
2015-06-14 16:22:02 +00:00
|
|
|
except (SSLError, moves.http_client.HTTPException, socket.error):
|
2017-10-17 15:43:28 +00:00
|
|
|
result = 'Connection failed'
|
|
|
|
self._log_error(result)
|
2014-03-10 05:18:05 +00:00
|
|
|
else:
|
2017-10-17 15:43:28 +00:00
|
|
|
response = http_handler.getresponse()
|
|
|
|
result = None
|
|
|
|
|
|
|
|
if 200 != response.status:
|
|
|
|
if 410 == response.status:
|
|
|
|
result = u'Authentication, %s (bad API key?)' % response.reason
|
|
|
|
else:
|
|
|
|
result = 'Http response code "%s"' % response.status
|
|
|
|
|
|
|
|
self._log_error(result)
|
|
|
|
|
|
|
|
return self._choose((True, 'Failed to send notification: %s' % result)[bool(result)], not bool(result))
|
2014-03-25 05:57:24 +00:00
|
|
|
|
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
notifier = PushalotNotifier
|