Skip to content

Instantly share code, notes, and snippets.

@monokal
Last active December 26, 2017 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monokal/c7cc611e328dccb89484f893e3a8b327 to your computer and use it in GitHub Desktop.
Save monokal/c7cc611e328dccb89484f893e3a8b327 to your computer and use it in GitHub Desktop.
Automatically stop completed/seeding torrents in Transmission.
#!/usr/bin/env python3
#
# Please don't use this unless you have a legitimate reason.
# Give back. Don't be a cunt.
#
import sys
import time
from termcolor import colored
import transmissionrpc
class Parasite(object):
def __init__(self, host, port):
try:
self.client = transmissionrpc.Client(host, port=port)
except Exception as e:
print(
"Failed to connect to Transmission with the error:\n{}".format(
e))
sys.exit(1)
print(
colored("Connected to Transmission ({}:{}).".format(host, port),
'blue'))
def __call__(self, interval):
while True:
print(
colored("Checking for seeding torrents (every {}s)...".format(
interval), 'blue'))
try:
torrents = self.client.get_torrents()
except Exception as e:
print("Failed to retrieve torrents with the error:\n{}".format(
e))
sys.exit(1)
for t in torrents:
if t.status == 'seeding':
self.client.stop_torrent(t.hashString)
print(
colored("{} was {}. Now stopped.".format(
t.name, t.status), 'red'))
else:
print(
colored("{} is {}. Doing nothing.".format(
t.name, t.status), 'green'))
time.sleep(interval)
if __name__ == '__main__':
parasite = Parasite(host='localhost', port=9091)
parasite(interval=30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment