[SCRIPT] sabToPushBullet

Come up with a useful post-processing script? Share it here!
Post Reply
spants
Newbie
Newbie
Posts: 3
Joined: May 7th, 2014, 6:57 pm

[SCRIPT] sabToPushBullet

Post 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
huleboeren
Release Testers
Release Testers
Posts: 114
Joined: January 25th, 2008, 1:10 pm

Re: [SCRIPT] sabToPushBullet

Post by huleboeren »

<3 PushBullet

Thanks to the orig. script author and you!
polayer5
Newbie
Newbie
Posts: 19
Joined: August 7th, 2013, 8:31 pm

Re: [SCRIPT] sabToPushBullet

Post by polayer5 »

Any chance this could be used or adapted for use with Windows 7?
spants
Newbie
Newbie
Posts: 3
Joined: May 7th, 2014, 6:57 pm

Re: [SCRIPT] sabToPushBullet

Post 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.
brodi6
Newbie
Newbie
Posts: 1
Joined: September 16th, 2014, 11:10 am

Re: [SCRIPT] sabToPushBullet

Post by brodi6 »

Where can I find more info and/or detailed instructions for implementing this script on my system? TIA!
blindpet
Newbie
Newbie
Posts: 28
Joined: July 13th, 2014, 7:51 am
Contact:

Re: [SCRIPT] sabToPushBullet

Post by blindpet »

brodi6, I made a guide for rtorrent that you can adapt pushbullet script
Post Reply