diff options
author | Christian Segundo | 2024-07-23 21:43:05 +0200 |
---|---|---|
committer | Christian Segundo | 2024-07-23 21:43:05 +0200 |
commit | 362af4e16d7cdfa1512a6f2f154f055907b4d900 (patch) | |
tree | f0e8817df1cad49bd466c60016cdd8b70913690c /scripts/delete-based-on-tag.py | |
parent | 076b6aefd5b17cccc34cc403b7b4f2ba4f093a57 (diff) | |
download | transmission-hacks-362af4e16d7cdfa1512a6f2f154f055907b4d900.tar.gz |
add ci
Diffstat (limited to 'scripts/delete-based-on-tag.py')
-rwxr-xr-x | scripts/delete-based-on-tag.py | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/scripts/delete-based-on-tag.py b/scripts/delete-based-on-tag.py deleted file mode 100755 index 37442cb..0000000 --- a/scripts/delete-based-on-tag.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python3 -import click -from transmission_rpc import Client -from datetime import timedelta, datetime - - -def convert_to_seconds(s): - units = {"s": "seconds", "m": "minutes", - "h": "hours", "d": "days", "w": "weeks"} - count = int(s[:-1]) - unit = units[s[-1]] - td = timedelta(**{unit: count}) - return td.seconds + 60 * 60 * 24 * td.days - - -@click.command() -@click.option('--port', default=9091) -@click.option('--host', default="localhost") -@click.option('--tag', required=True) -@click.option('--age', default='1w') -def main(host, port, tag, age): - """ Deletes torrents older than the specified age. """ - - c = Client(host=host, port=port) - torrents = c.get_torrents() - for torrent in torrents: - if tag not in torrent.labels: - continue - if torrent.done_date is None: - continue - - specified_age = convert_to_seconds(age) - age_in_seconds = int((datetime.today().timestamp() - - torrent.done_date.timestamp())) - - if age_in_seconds > specified_age: - print(f"Deleting {torrent.name}") - c.remove_torrent(torrent.id, delete_data=True) - - -if __name__ == '__main__': - main() |