Page 1 of 1

[SCRIPT] sabToPushBullet

Posted: May 7th, 2014, 7:08 pm
by spants
Hi

I modified the sabToPushover script (sorry - I dont know the author to give credit) to work with PushBullet

Forgot to mention that this is running for me on Linux (Ubuntu) and uses CURL to talk to pushbullet.

Two files are required:

sabToPushBullet.py

Code: Select all

#!/usr/bin/env python

import sys
import httplib
import urllib
import os.path
import logging
import ConfigParser
import subprocess

ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter('%(asctime)s [%(name)s] %(levelname)s: %(message)s'))

logger = logging.getLogger("PushBullet.sab")
logger.setLevel(logging.DEBUG)
logger.addHandler(ch)

def readConfig(configName) :
	config = ConfigParser.ConfigParser()
	file = os.path.join(os.path.dirname(sys.argv[0]), configName)

	if not os.path.isfile(file):
		print "ERROR: You need a {0} config file!".format(configName)
		sys.exit(-1)

	try:
		fp = open(file, "r")
		config.readfp(fp)
		fp.close()
	except IOError, e:
		print "Could not read configuration file: ", str(e)
		sys.exit(1)		

	return config

def PushBullet(dirname, nzbName=None, cleanJobName=None, statusCode=0) :

	logger.info("Sending notification for job '%s', status %s", cleanJobName, statusCode)	

	config  = readConfig("sabToPushBullet.cfg")
	api     = config.get("PushBullet", "api")
	iden    = config.get("PushBullet", "device_iden")

	logger.info("api %s", api)

	status = int(statusCode)		

	# message title
	title = "Download complete"	
	if status > 0: "Download failed"

	# message detail 
	message = "Downloaded {0} successfully".format(cleanJobName)		
	if status == 1: message = "Failed to verify nzb {0}".format(nzbName)
	if status == 2: message = "Failed to unpack {0}".format(cleanJobName)		
	if status > 2: message = "Failed to verify and unpack {0}".format(cleanJobName)		

	# the message priority for errors
	priority = 0 
	if status > 0 and error_priority > 0: priority = 1	

	# call pushbullet
	vcl='curl https://api.pushbullet.com/api/pushes -u "%s": -d device_iden="%s" -d type=note -d title="%s" -d body="%s" -X POST -s -S > /dev/null' % (api,iden,title,message)
	x = subprocess.Popen(vcl,shell=True)

	logger.info("Message { title: '%s', message: '%s' }", title, message)

if len(sys.argv) < 2:
    print "No folder supplied - is this being called from SABnzbd?"
    sys.exit()
elif len(sys.argv) >= 3:
    PushBullet(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[7])
else:
    PushBullet(sys.argv[1])
and the config file

sabToPushBullet.cfg

Code: Select all

[PushBullet]
api=(apikey without the :)
device_iden=(can be left blank and will send to all your devices)
Have fun
Spants

Re: [SCRIPT] sabToPushBullet

Posted: May 19th, 2014, 11:01 am
by huleboeren
<3 PushBullet

Thanks to the orig. script author and you!

Re: [SCRIPT] sabToPushBullet

Posted: June 23rd, 2014, 7:53 am
by polayer5
Any chance this could be used or adapted for use with Windows 7?

Re: [SCRIPT] sabToPushBullet

Posted: June 30th, 2014, 12:52 am
by spants
Sorry for the delay in replying. I am sure that this can be done.
It requires python (which should have been installed)
and a windows version of curl.

There have been a lot of pushbullet libraries released since I wrote this so it may be even easier to do now.

Re: [SCRIPT] sabToPushBullet

Posted: September 16th, 2014, 11:19 am
by brodi6
Where can I find more info and/or detailed instructions for implementing this script on my system? TIA!

Re: [SCRIPT] sabToPushBullet

Posted: September 17th, 2014, 6:08 am
by blindpet
brodi6, I made a guide for rtorrent that you can adapt pushbullet script