1
0
Fork 0
mirror of https://github.com/evilhero/mylar synced 2024-12-23 16:22:45 +00:00

FIX: Pushbullet notifcations fixed (will send to all pushbullet devices assigned to provided pushbullet apikey currently)

This commit is contained in:
evilhero 2015-01-31 17:21:42 -05:00
parent 950c843a76
commit c730c59552
3 changed files with 33 additions and 48 deletions

View file

@ -954,10 +954,11 @@
</div>
<div class="row">
<label>API Key</label><input type="text" name="pushbullet_apikey" value="${config['pushbullet_apikey']}" size="50">
<small>Warning: Will send to ALL your pushbullet devices</small>
</div>
<div class="row">
<label>Device ID</label><input type="text" name="pushbullet_deviceid" value="${config['pushbullet_deviceid']}" size="50">
<!-- <label>Pushbullet device list</label>
<!-- <label>Device ID</label><input type="text" name="pushbullet_deviceid" value="${config['pushbullet_deviceid']}" size="50">
<label>Pushbullet device list</label>
<select name="pushbullet_device_list" id="pushbullet_device_list"></select>
<input type="hidden" id="pushbullet_deviceid" value="${config['pushbullet_deviceid']}" />
<input type="button" class="btn" value="Update device list" id="getPushbulletDevices" />

View file

@ -25,6 +25,7 @@ import os.path
import subprocess
import time
import lib.simplejson as simplejson
import json
# This was obviously all taken from headphones with great appreciation :)
@ -301,64 +302,47 @@ class PUSHBULLET:
http_handler = HTTPSConnection("api.pushbullet.com")
#possible needed for update.
#if method == 'GET':
# uri = '/v2/devices'
#else:
# method = 'POST'
# uri = '/v2/pushes'
#authString = base64.encodestring('%s:' % (self.apikey)).replace('\n', '')
#if method == 'GET':
# http_handler.request(method, uri, None, headers={'Authorization': 'Basic %s:' % authString})
#else:
# if snatched:
# if snatched[-1] == '.': snatched = snatched[:-1]
# event = snline
# message = "Mylar has snatched: " + snatched + " from " + prov + " and has sent it to " + sent_to
# else:
# event = prline + ' complete!'
# message = prline2
# data = {'device_iden': self.deviceid,
# 'type': "note",
# 'title': event.encode('utf-8'), #"mylar",
# 'body': message.encode('utf-8') }
# http_handler.request(method, uri, body=urlencode(data), headers={'Authorization': 'Basic %s' % authString})
if snatched:
if snatched[-1] == '.': snatched = snatched[:-1]
event = snline
message = "Mylar has snatched: " + snatched + " from " + prov + " and has sent it to " + sent_to
if method == 'GET':
uri = '/v2/devices'
else:
event = prline + ' complete!'
message = prline2
method = 'POST'
uri = '/v2/pushes'
data = {'device_iden': mylar.PUSHBULLET_DEVICEID,
'type': "note",
'title': event,
'body': message.encode("utf-8")}
authString = base64.b64encode(self.apikey + ":")
if method == 'GET':
http_handler.request(method, uri, None, headers={'Authorization': 'Basic %s:' % authString})
else:
if snatched:
if snatched[-1] == '.': snatched = snatched[:-1]
event = snline
message = "Mylar has snatched: " + snatched + " from " + prov + " and has sent it to " + sent_to
else:
event = prline + ' complete!'
message = prline2
data = {'type': "note", #'device_iden': self.deviceid,
'title': event.encode('utf-8'), #"mylar",
'body': message.encode('utf-8') }
http_handler.request("POST",
"/api/pushes",
headers = {'Content-type': "application/x-www-form-urlencoded",
'Authorization': 'Basic %s' % base64.b64encode(mylar.PUSHBULLET_APIKEY + ":") },
body = urlencode(data))
"/v2/pushes",
headers = {'Content-type': "application/json",
'Authorization': 'Basic %s' % base64.b64encode(mylar.PUSHBULLET_APIKEY + ":")},
body = json.dumps(data))
response = http_handler.getresponse()
request_body = response.read()
request_status = response.status
logger.fdebug(u"PushBullet response status: %r" % request_status)
logger.fdebug(u"PushBullet response headers: %r" % response.getheaders())
logger.fdebug(u"PushBullet response body: %r" % response.read())
#logger.fdebug(u"PushBullet response status: %r" % request_status)
#logger.fdebug(u"PushBullet response headers: %r" % response.getheaders())
#logger.fdebug(u"PushBullet response body: %r" % response.read())
if request_status == 200:
if method == 'GET':
return request_body
else:
logger.fdebug(module + ' PushBullet notifications sent.')
logger.info(module + ' PushBullet notifications sent.')
return True
elif request_status >= 400 and request_status < 500:
logger.error(module + ' PushBullet request failed: %s' % response.reason)

View file

@ -1820,7 +1820,7 @@ def notify_snatch(nzbname, sent_to, modcomicname, comyear, IssueNumber, nzbprov)
if mylar.PUSHBULLET_ENABLED and mylar.PUSHBULLET_ONSNATCH:
logger.info(u"Sending Pushbullet notification")
pushbullet = notifiers.PUSHBULLET()
pushbullet.notify(snline=snline,snatched=nzbname,sent_to=sent_to,prov=nzbprov)
pushbullet.notify(snline=snline,snatched=nzbname,sent_to=sent_to,prov=nzbprov,method='POST')
return