[Python] Post to Twitter script

Come up with a useful post-processing script? Share it here!
Post Reply
nock
Newbie
Newbie
Posts: 28
Joined: October 29th, 2014, 2:55 pm

[Python] Post to Twitter script

Post by nock »

I made a small and easy python script to update Twitter.

All you need is python and Tweepy libary, and create a twitter "app"
Remember to set the permissions to read/write in the twitter app.

Install tweepy (linux).

Code: Select all

pip install tweepy
Past this code to a ".py" file and save it in your post-process folder.

Code: Select all

import tweepy
import sys
# Update Twitter with Sabnzbd downloads
try:
(scriptname,directory,orgnzbname,jobname,reportnumber,category,group,postprocstatus,url) = sys.argv
except:
try:
#getting clean jobname from sabnznd
jobname = sys.argv[3]

except:
print "No commandline parameters found"
sys.exit(1)

CONSUMER_KEY = 'past consumer key'
CONSUMER_SECRET = 'past consumer secret'
ACCESS_TOKEN_KEY= 'past access token'
ACCESS_TOKEN_SECRET= 'past access token secret'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.secure = True
auth.set_access_token(ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
api.update_status(status="Sabnzbd: Download Finished: "+jobname)
This will update Twitter with: "Sabnzbd: Download Finished:" + jobname of the download.
Edit the last line if you would like to post something els :)

How to import the library in Windows i sadly do not know:/
Post Reply