Skip to content

Instantly share code, notes, and snippets.

@xthesaintx
Created March 22, 2022 01:14
Show Gist options
  • Save xthesaintx/bb759aa84fcad3d33c2c3a8738ca5524 to your computer and use it in GitHub Desktop.
Save xthesaintx/bb759aa84fcad3d33c2c3a8738ca5524 to your computer and use it in GitHub Desktop.
Script that will remove completed torrents that are older than 7 days from the QbitTorrent queue
import qbittorrentapi
import datetime
today = datetime.datetime.now()
#Set age (days) to remove
older = 7
#Converts UTC time to datetime
def utc(x):
dt = datetime.datetime.fromtimestamp(x)
return (dt)
#Returns int of days between two datetimes
#y = latest (today), z = oldest
def days_since(y,z):
x = y-z
return x.days
# Set Variables
qbit_ip ="192.168.0.122:8080"
# instantiate a Client using the appropriate WebUI configuration
qbt_client = qbittorrentapi.Client(host=qbit_ip, username='admin', password='adminadmin')
try:
qbt_client.auth_log_in()
except qbittorrentapi.LoginFailed as e:
print(e)
for torrent in qbt_client.torrents_info(statusfilter="completed", reverse=True):
if days_since(today,utc(torrent.completion_on))>older:
# print (torrent.name)
qbt_client.torrents_delete(delete_files=False, torrent_hashes=torrent.hash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment