[Python] Sabnzbd Pushover notifications

Come up with a useful post-processing script? Share it here!
Post Reply
b0wter
Newbie
Newbie
Posts: 2
Joined: October 16th, 2012, 5:02 am

[Python] Sabnzbd Pushover notifications

Post by b0wter »

Yesterday I've stumbled across Pushover notifications (which is available for Android and iOS devices) and decided to put together a little script that would allow me to receive notifications on my download status.
I'm no python expert so don't expect the script to be super elegant ;]

Code: Select all

#!/usr/bin/python

import httplib, urllib, sys

message = "" #"Download of " + sys.argv[3] + " "
serverurl = "$SERVER_URL"

print("Convertig argument " + sys.argv[7] + " to status.")
if(int(sys.argv[7]) == 0):
        message = "Download of " + sys.argv[3] + " has been completed."
elif(int(sys.argv[7]) == 1):
        message = "Verification of " + sys.argv[3] + " failed."
elif(int(sys.argv[7]) == 2):
        message = "Unpacking of " + sys.argv[3] + " failed."
elif(int(sys.argv[7]) == 3):
        message = "Verification and unpacking of " + sys.argv[3] + " failed."

print("Establishing http connection.")
conn = httplib.HTTPSConnection("api.pushover.net:443")
print("Handling request.")
conn.request("POST", "/1/messages.json",
  urllib.urlencode({
    "token": "$API_KEY",
    "user": "$USER_KEY",
    "message": message,
    "url": serverurl,
    "url_title": "Visit web interface",
  }), { "Content-type": "application/x-www-form-urlencoded" })
print("Waiting for response.")
conn.getresponse()
print("Notification send.")
There are three values to change: $USER_KEY, $API_KEY and $SERVER_URL.
The $USER_KEY is straight forward, you can find it when logging into your Pushover account.
Generating the $API_KEY is a little trickier but still easy ;]
Log into your account, go to "Apps & Plugins", select "Create a new application" and enter a name, select an icon (selection of pictures). Finally click on "Create application" and write down your api key.
Unfortunately this has to be done as Pushover limites the monthly API calls.
Replacing the server URL is optional but if you enter the URL of your Sabnzbd you can easily open the webpage if a download fails.

When you're done entering the values put the file into your sabnzbd scripts folder and make sure it's executable and accessible to the user hosting the sabnzbd process.
From the "Categories" page of your sabnzbd web interface you can now select the script.
EightBall
Newbie
Newbie
Posts: 2
Joined: October 19th, 2012, 10:55 pm

Re: [Python] Sabnzbd Pushover notifications

Post by EightBall »

Great work, b0wter. Tested it and it works just as expected.

All I had to change was line 8 to "Converting" and line 31 to "Notification sent."

It would be great if pushover could be incorporated directly in sabnzbd, it already is in couchpotato and sickbeard.
b0wter
Newbie
Newbie
Posts: 2
Joined: October 16th, 2012, 5:02 am

Re: [Python] Sabnzbd Pushover notifications

Post by b0wter »

Thank you. Actually, you should be able to remove the output. I've just inserted them to test some stuff :]
elcabong
Newbie
Newbie
Posts: 3
Joined: November 5th, 2012, 11:34 am

Re: [Python] Sabnzbd Pushover notifications

Post by elcabong »

I really wanted to use this on Windows, but it wasn't easy so I thought I'd share what I did to get it working. First, I assume that you have Python installed on your Windows PC.

The most important step is to ensure that the path to your Python installation is in the Windows environment variable. There is a detailed description of how to do that in section 3.3.1 and 3.3.2 in the Python documentation here: http://docs.python.org/2/using/windows.html . You have to do it logged on with an account with administrator privileges. Once you've added the path to the environmental variables, restart your PC. To test that it works, open a command prompt and type python, you should get a Python prompt, if you get "'python' is not recognized as an internal or external command,operable program or batch file." there is something wrong with your environment variable.

Next, when you create the script, name it with the .pyw extension (e.g. postprocess.pyw). This tells python to run the script in the background.

Here is the tricky part. SABnzbd for Windows will only recognize scripts that end in .bat or .cmd . You cannot simply create a batch file to run the python script because the variables from SABNzbd will not be passed to the python script (this kicked my butt for a while). So if you were to go to the Categories config page in SABNzbd your python script would not show up in the drop down because it is not a .bat or .cmd file. So what you have to do is manually edit your sabnzbd.ini file and add the path to your script in the ini. Look for a section in the ini that starts with:

Code: Select all

[categories]
[[*]]
and change the line that says "script = " to the name of your python script. In my case that section looks like this:

Code: Select all

[categories]
[[*]]
priority = 0
pp = 3
name = *
script = postprocess.pyw
newzbin = ""
dir = ""
I don't know if it matters, but for grins I restarted SABNzbd and voila, Python notification goodness!

Thank you to b0wter for the script! Wanna do a pre-process script for when files are added? ;D
Richard63
Newbie
Newbie
Posts: 17
Joined: January 18th, 2015, 3:58 pm

Re: [Python] Sabnzbd Pushover notifications

Post by Richard63 »

for pre-proces script see my posting.
Post Reply