Python Script for specific variables?

Suggestions and discussion of future versions
pyrodex
New User
New User
Posts: 4
Joined: Sat Jun 22, 2013 10:37 pm
OS or Distro: Ubuntu

Python Script for specific variables?

Postby pyrodex » Wed May 31, 2017 5:19 pm

I am looking to code a script to output the Label, Name, And the time the torrent was added to deluge but can't find a simple script to do that and the documentation is lacking.... Here is what I have playing with both seeding time and time added.

Code: Select all

#!/usr/bin/python

import os
import sys
import string
import syslog

# Import the client module
from deluge.ui.client import client
# Import the reactor module from Twisted - this is for our mainloop
from twisted.internet import reactor
from twisted.internet import defer

# Set up the logger to print out errors
from deluge.log import setupLogger
setupLogger()
syslog.syslog('deluge test: the script started running')

label=""
name=""
seeding_time=""
time_added=""

# Connect to a daemon running on the localhost
# We get a Deferred object from this method and we use this to know if and when
# the connection succeeded or failed.
d = client.connect()

# Torrent ID is passed from deluge execute plugin
torrent_id = sys.argv[1]

# We create a callback function to be called upon a successful connection
def on_connect_success(result):
    #print "Connection was successful!"
    def on_get_torrent(torrent):
        global label
        label=torrent["label"]
        name=torrent["name"]
        added=torrent["seeding_time"]
        added=torrent["time_added"]
        print label
        print name
        print seeding_time
        print time_added
        client.disconnect()
        reactor.stop()

    client.core.get_torrent_status(torrent_id, ["label","name","seeding_time","time_added"]).addCallback(on_get_torrent)

# We add the callback to the Deferred object we got from connect()
d.addCallback(on_connect_success)

# We create another callback function to be called when an error is encountered
def on_connect_fail(result):
    print "Connection failed!"
    print "result:", result

# We add the callback (in this case it's an errback, for error)
d.addErrback(on_connect_fail)

# Run the twisted main loop to make everything go
reactor.run()


Any help is appreciated!

Cas
Top Bloke
Top Bloke
Posts: 3426
Joined: Mon Dec 07, 2009 6:04 am
OS or Distro: Ubuntu 16.04
Location: Scotland

Re: Python Script for specific variables?

Postby Cas » Thu Jun 01, 2017 4:56 pm

Can you be a bit more specific with your question, thanks

pyrodex
New User
New User
Posts: 4
Joined: Sat Jun 22, 2013 10:37 pm
OS or Distro: Ubuntu

Re: Python Script for specific variables?

Postby pyrodex » Thu Jun 01, 2017 6:07 pm

Cas wrote:Can you be a bit more specific with your question, thanks


Basically I'd like to have a python script I can feed a single torrent ID too that would then produce the label, torrent name, and how long the torrents been in the system or how long it has been seeding for printed out. I am able to get the label and torrent name with my script but have no idea how to get the added time or the seeding period time.

Cas
Top Bloke
Top Bloke
Posts: 3426
Joined: Mon Dec 07, 2009 6:04 am
OS or Distro: Ubuntu 16.04
Location: Scotland

Re: Python Script for specific variables?

Postby Cas » Thu Jun 01, 2017 7:52 pm

Code: Select all

        added=torrent["seeding_time"]
        added=torrent["time_added"]


You have a typo in your variable assignment


Return to “Development”

Who is online

Users browsing this forum: No registered users and 2 guests