Skip to content

Instantly share code, notes, and snippets.

@fangelion
Created April 14, 2015 18:47
Show Gist options
  • Save fangelion/0fb03e02b74ed51c6e1e to your computer and use it in GitHub Desktop.
Save fangelion/0fb03e02b74ed51c6e1e to your computer and use it in GitHub Desktop.
import sys
import transmissionrpc
import re
import os
def find_bed_torrents():
#CLIENT_NAME = "transmission"
DEFAULT_URL = "http://localhost:9091/transmission/rpc"
server = transmissionrpc.Client(DEFAULT_URL)
list_torrents = []
deleted_torrents = []
for torrent in server.get_torrents():
# print(torrent.torrentFile)
list_torrents.append(os.path.basename(torrent.torrentFile))
if torrent:
# print(i)
torrent_dir = os.path.dirname(torrent.torrentFile)
# print(torrent_dir)
if not list_torrents:
exit()
if torrent_dir:
for i in os.listdir(torrent_dir):
if i not in list_torrents:
deleted_torrents.append(i)
os.remove(torrent_dir + "/" + i)
if len(deleted_torrents) > 0:
print("Deleting torrent files not in client")
for i in deleted_torrents:
print(" - ", i)
def test_(filter, args):
added = re.compile(filter, re.M).findall(args)
if len(added) > 0:
for i in added:
print(i)
with open("/home/user/rtf.log", "a") as log:
log.write(args)
def filter_rtfetch(args):
tests = [
"\[\+\].*",
"^\s+\+.*",
"^\s+~.*",
"^\s+-.*"
]
with open("/home/user/rtfetch_log", "a") as log_full:
log_full.write(args)
for string in args.split("\n"):
for test in tests:
test_(test, string)
filter_rtfetch(sys.stdin.read())
find_bed_torrents()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment