Source

TransmissionScripts / transmission-list.py

Full commit
#!/usr/bin/env python2.7

import argparse
import datetime

import transmissionrpc

ID_WIDTH = 5
NAME_WIDTH = 77
STATUS_WIDTH = 15
PROG_WIDTH = 8
RATIO_WIDTH = 8
AGE_WIDTH = 15

def FormatTD(self): 
    hours = self.seconds // 3600 
    minutes = (self.seconds % 3600) // 60 
    seconds = self.seconds % 60 
    return '%02d:%02d:%02d:%02d' % (self.days, hours, minutes, seconds) 

def Main():
    options = argparse.ArgumentParser(description='Removes all torrents on a given host that are either older then the given days or have a larger then given ratio')
    options.add_argument('-p', '--port', default='9091', help='port to connect on. default=9091')
    options.add_argument('-u', '--user', default='', help='The user to connect as. Defaults to empty')
    options.add_argument('-w', '--password', default='', help='The password to connect with.  Default is empty')
    options.add_argument('host', default='localhost', help='the host to connect to. default=localhost')
    theargs = options.parse_args()
    
    tc = transmissionrpc.Client(theargs.host, theargs.port, theargs.user, theargs.password)
    tl = tc.info()
    
    print 'ID'.ljust(ID_WIDTH) + \
    'Name'.ljust(NAME_WIDTH) + \
    'Status'.ljust(STATUS_WIDTH) + \
    'Prog'.ljust(PROG_WIDTH) + \
    'Ratio'.ljust(RATIO_WIDTH) + \
    'Age'.ljust(AGE_WIDTH)
         
    for t in tl:
        print str(t).ljust(ID_WIDTH) + \
        tl[t].name.ljust(NAME_WIDTH) + \
        tl[t].status.ljust(STATUS_WIDTH) + \
        str(round(tl[t].progress,2)).ljust(PROG_WIDTH) + \
        str(round(tl[t].ratio,2)).ljust(RATIO_WIDTH) + \
        FormatTD(datetime.datetime.now() - tl[t].date_added).ljust(AGE_WIDTH)
  
if __name__ == '__main__':
    Main()