Twitter Notification

Feature requests not specific to either the Mac OS X or GTK+ versions of Transmission
Post Reply
vgbnd
Posts: 1
Joined: Mon Apr 13, 2009 5:31 pm

Twitter Notification

Post by vgbnd »

helo.
thanks for transmission. wonderful app.

would be great if you could integrate Twitter Support. Transmission could send a Direct Message to a preconf Twitter account when a download has finished. should be not to hard to integrate via the Twitter API.
livings124
Transmission Developer
Posts: 3142
Joined: Fri Jan 13, 2006 8:08 pm

Re: Twitter Notification

Post by livings124 »

This is clear and obvious bloat. My only recommendation at all for this is see if the Growl developers are interested in adding a twitter module.
Jordan
Transmission Developer
Posts: 2312
Joined: Sat May 26, 2007 3:39 pm
Location: Titania's Room

Re: Twitter Notification

Post by Jordan »

vgbnd wrote:helo.
thanks for transmission. wonderful app.

would be great if you could integrate Twitter Support. Transmission could send a Direct Message to a preconf Twitter account when a download has finished. should be not to hard to integrate via the Twitter API.
I will burn the code to the ground and salt the earth before this feature is added into Transmission's core.

That said, it would be very easy -- literally, maybe 20-30 lines -- for someone to write a Python script to use JSON/RPC to sniff out completed torrents on a Transmission session, and submit them to Twitter.
thinkmusic
Posts: 1
Joined: Wed May 06, 2009 3:14 am

Re: Twitter Notification

Post by thinkmusic »

Here's a simple proof-of-concept that could be run as a cron job every five minutes (it will direct message a specified user with the torrent name and "is done" for each torrent that has completed in the past five minutes:

import http.client, json, base64, time
from datetime import datetime, timedelta
server = http.client.HTTPConnection('localhost:9091')
twitterserver = http.client.HTTPConnection('twitter.com')
basic_auth = base64.b64encode(b'USERNAME:PASSWORD') #Replace USERNAME and PASSWORD with the account name and password to use to send the message from.
requestheader = {'Authorization':'Basic ' + bytes.decode(basic_auth)}
o = json.dumps({ 'arguments': {'fields': ['id','name','doneDate']},'method': 'torrent-get'},sort_keys=False, indent=4)
server.request("POST","/transmission/rpc/",o)
rawdata=server.getresponse().read().decode()
data=json.loads(rawdata)
darray = [{'id':x['id'], 'date':datetime.fromtimestamp(x['doneDate'])} for x in data['arguments']['torrents']]
curr = [x for x in darray if datetime.now() - x['date'] < timedelta(minutes=5)]

def dmself(mess):
print(mess)
twitterserver.request("POST","/direct_messages/new.json","user=TARGETUSERNAME&text="+mess,requestheader) #Replace TARGETUSERNAME with the account name to send the message to
twitterserver.getresponse()
if len(curr) > 0:
[dmself([y for y in data['arguments']['torrents'] if y['id'] == x['id']][0]['name'] + " is done.") for x in curr]
Post Reply