Suggest, post, or discuss plugins for Deluge
colbert
Member
Posts: 10 Joined: Wed Mar 30, 2011 12:50 am
Post
by colbert » Tue Jun 28, 2011 8:43 pm
I see Active Time and Seeding Time, and the math is simple enough of course, but I have an automated script to send me an email when torrent is complete, and I'm wondering how I can add in the email a little blurb with the time it took to complete the torrent download?
This is the email script I am using:
Code: Select all
#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3
subject="Started download new torrent!"
message="$torrentname to $torrentpath"
echo -e `date`"::Finished downloading torrent:$2 in: $3" with id:$torrentid >> ~/logs/scripts.log
echo -e `sendEmail -t my@email.com -f my@email.com -u "deluge server notification: torrent $torrentname is complete!" -m "$torrentname has completed downloading at: $torrentpath :)" -xu my@email.com -xp password -v -o tls=yes -s email.com` >> ~/logs/scripts.log
CSB
Leecher
Posts: 66 Joined: Fri Dec 03, 2010 1:55 am
Post
by CSB » Tue Jun 28, 2011 10:46 pm
Code: Select all
#!/usr/bin/python
import sys
from datetime import datetime, date, time
from deluge.ui.client import client
from twisted.internet import reactor
d = client.connect()
def on_connect_success(result):
def on_get_torrent_value(torrent):
print str(datetime.fromtimestamp(torrent["active_time"]) - datetime.fromtimestamp(0))
client.disconnect()
reactor.stop()
client.core.get_torrent_status(sys.argv[1], ["active_time"]).addCallback(on_get_torrent_value)
d.addCallback(on_connect_success)
def on_connect_fail(result):
pass
d.addErrback(on_connect_fail)
reactor.run()
The python script above will return the active time of a torrentid. Call it from your bash script. Since you're calling that bash script as soon as you finish, the seeding time is zero, and the active time is all downloading, no math is needed involving the seeding time.
colbert
Member
Posts: 10 Joined: Wed Mar 30, 2011 12:50 am
Post
by colbert » Wed Jun 29, 2011 2:49 am
Thanks! How should I call it from my script?
CSB
Leecher
Posts: 66 Joined: Fri Dec 03, 2010 1:55 am
Post
by CSB » Wed Jun 29, 2011 6:58 am
colbert wrote: Thanks! How should I call it from my script?
Just pass it $1 and it will return a string.
colbert
Member
Posts: 10 Joined: Wed Mar 30, 2011 12:50 am
Post
by colbert » Wed Jun 29, 2011 8:21 pm
CSB wrote: colbert wrote: Thanks! How should I call it from my script?
Just pass it $1 and it will return a string.
Sorry mate I'm pretty bad with bash lol, my script is:
Code: Select all
#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3
subject="Started download new torrent!"
message="$torrentname to $torrentpath"
echo -e `date`"::Finished downloading torrent:$2 in: $3" with id:$torrentid >> ~/logs/scripts.log
echo -e `sendEmail -t my@email.com -f my@email.com -u "deluge server notification: torrent $torrentname is complete!" -m "$torrentname has completed downloading at: $torrentpath :)" -xu my@email.com -xp password -v -o tls=yes -s email.com` >> ~/logs/scripts.log
So I reckon I add:
in there? But how do I reference this separate script? If I'm explaining badly what I mean is I want, in the email from this script, to include the time of downloading as per your script. I'm just confused how exactly I combine both. Thanks a lot for your help
CSB
Leecher
Posts: 66 Joined: Fri Dec 03, 2010 1:55 am
Post
by CSB » Wed Jun 29, 2011 9:39 pm
No.
Save that text as a torrentTimeDelta.py file, chmod +x it, and put it in your PATH.
In your script add
Code: Select all
torrenttimedelta=`python torrentTimeDelta.py $1`
Then, you can use $torrenttimedelta where you want the time.
colbert
Member
Posts: 10 Joined: Wed Mar 30, 2011 12:50 am
Post
by colbert » Thu Jun 30, 2011 12:05 am
Okay this is what I have put:
Code: Select all
#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3
torrenttimedelta=`python /home/bobby/scripts/deluge/torrentTimeDelta.py $1`
subject="Started download new torrent!"
message="$torrentname to $torrentpath"
echo -e `date`"::Finished downloading torrent:$2 in: $3" with id:$torrentid >> ~/logs/scripts.log
echo -e `sendEmail -t my@email.com -f my@email.com -u "deluge server notification: torrent $torrentname is complete!" -m "$torrentname has completed downloading at: $torrentpath and took $torrenttimedelta to complete :)" -xu my@email.com -xp password -v -o tls=yes -s email.com` >> ~/logs/scripts.log
echo ---------------------------------------- >> ~/logs/scripts.log
However, where the time should be I'm getting an empty space so it just says "and took to complete
".
CSB
Leecher
Posts: 66 Joined: Fri Dec 03, 2010 1:55 am
Post
by CSB » Thu Jun 30, 2011 12:50 am
Get a torrentid, and try calling the script manually.
The following will print all torrent ids.
Code: Select all
#!/usr/bin/python
from deluge.ui.client import client
from twisted.internet import reactor
d = client.connect()
def on_connect_success(result):
print "Connection was successful!"
def on_get_torrent_value(value):
for torrent in value:
print "%s: %s" % (torrent, value[torrent]["name"])
client.disconnect()
reactor.stop()
client.core.get_torrents_status({}, ["name"]).addCallback(on_get_torrent_value)
d.addCallback(on_connect_success)
def on_connect_fail(result):
print "Connection failed!"
print "result:", result
d.addErrback(on_connect_fail)
reactor.run()
colbert
Member
Posts: 10 Joined: Wed Mar 30, 2011 12:50 am
Post
by colbert » Thu Jun 30, 2011 1:30 am
Ok I used that as torrentID.py and did:
Code: Select all
python2 torrentTimeDelta.py 363e9064f2af41f63e16779dc9dccf4b9cf0542d
2:48:16
So it works, but only manually?
CSB
Leecher
Posts: 66 Joined: Fri Dec 03, 2010 1:55 am
Post
by CSB » Thu Jun 30, 2011 1:45 am
Try calling the python script from the bash script using the same binary you did there.