Commits

anothergene  committed 6fe0625

rewrote the transmission remove script to accept arguments

  • Participants
  • Parent commits f03a6be

Comments (0)

Files changed (2)

File transmission-removedone.py

 #!/usr/bin/env python
-'''
-Created on Feb 5, 2011
+# encoding: utf-8
 
-@author: gmoreau
-'''
+import argparse
+import datetime
+import sys
 import transmissionrpc
-from datetime import datetime
 
-TRANS_HOST = '192.168.100.150'  # The host transmission is running on
-TRANS_PORT = '9091' # The port the host is listening on
-TRANS_USER =  ''    # The user id you have set
-TRANS_PW = ''   # the password you have set
-MAX_RATIO = 1.5
-MAX_RETENTION = 5
+def main(argv=None):
 
-def Main():
-    tc = transmissionrpc.Client(TRANS_HOST, TRANS_PORT, TRANS_USER, TRANS_PW)
+    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('-r', '--ratio', type=float, default=5.0, help='remove if ratio is larger. default=2.0')
+    options.add_argument('-d', '--days', type=int, default=10, help='remove if older then this in days. default=5')
+    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()
-    nothing_processed = True
+    nothingprocessed = True
+    
     for t in tl:
-        age = datetime.now() - tl[t].date_added
-        if (tl[t].status == 'stopped' and tl[t].ratio >= MAX_RATIO) or (age.days >= MAX_RETENTION ):
-            nothing_processed = False
+        age = datetime.datetime.now() - tl[t].date_added
+        
+        if (tl[t].status == 'stopped' and tl[t].ratio >= theargs.ratio) or (age.days >= theargs.days):
+            nothingprocessed = False
             print 'removing torrent ' + tl[t].name +' and data file.'
             tc.remove(t, True)
-    if nothing_processed :
+  
+    if nothingprocessed :
         print 'nothing due to be deleted, try again later'
-            
-if __name__ == '__main__':
-    Main()
-        
-        
-        
-               
+
+if __name__ == "__main__":
+    sys.exit(main())

File transmission-removedone2.py

-#!/usr/bin/env python
-# encoding: utf-8
-"""
-untitled.py
-
-Created by Gene Moreau on 2011-02-09.
-Copyright (c) 2011 __MyCompanyName__. All rights reserved.
-"""
-
-import sys
-import argparse
-import transmissionrpc
-
-
-help_message = '''
-help me.
-'''
-
-
-def main(argv=None):
-
-    options = argparse.ArgumentParser(description='options passed to progream')
-    options.parse_args()
-    
-    tc = transmissionrpc.Client(TRANS_HOST, TRANS_PORT, TRANS_USER, TRANS_PW)
-    tl = tc.info()
-    nothing_processed = True
-    
-         
-    for t in tl:
-        age = datetime.now() - tl[t].date_added
-        
-        if (tl[t].status == 'stopped' and tl[t].ratio >= MAX_RATIO) or (age.days >= MAX_RETENTION ):
-            nothing_processed = False
-            print 'removing torrent ' + tl[t].name +' and data file.'
-            tc.remove(t, True)
-  
-    if nothing_processed :
-        print 'nothing due to be deleted, try again later'
-
-
-if __name__ == "__main__":
-    sys.exit(main())