SHARE
TWEET

Untitled

a guest Oct 13th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. import sys
  5. import time
  6. from transmissionrpc import Client
  7.  
  8. jfx_purge = 1
  9. jfx_delta = jfx_purge * 86400
  10. jfx_epoch = int(time.time())
  11. transmission_base = '/transmission/'
  12. transmission_host = '192.168.0.254'
  13.  
  14. def purge_tmpfiles(root, list):
  15.   for l in sorted(list):
  16.     path = os.path.join(root, l)
  17.     delta = jfx_epoch - int(os.path.getctime(path))
  18.     if delta >= jfx_delta:
  19.       os.remove(path) if os.path.isfile(path) else os.rmdir(path)
  20.  
  21. def parse_tmpfiles():
  22.   if os.path.isdir(transmission_base):
  23.     for x in os.listdir(transmission_base):
  24.       path = os.path.join(transmission_base, x)
  25.       if os.path.isdir(path):
  26.         for root, dirs, files in os.walk(path, topdown=False):
  27.           purge_tmpfiles(root, files)
  28.           purge_tmpfiles(root, dirs)
  29.  
  30. def purge_torrents():
  31.   tc = Client(address=transmission_host)
  32.   torrent_list = tc.info()
  33.   if len(torrent_list) > 0:
  34.     for tid, torrent in torrent_list.items():
  35.       torrent_delta = jfx_epoch - int(torrent.addedDate)
  36.       if torrent_delta >= jfx_delta:
  37.         tc.stop_torrent(tid)
  38.         tc.remove_torrent(tid, delete_data=True)
  39.  
  40. if __name__ == '__main__':
  41.   purge_torrents()
  42.   parse_tmpfiles()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top