ansible/roles/torrent/files/torrentjsonstats.py
Kevin Fenzi 134510ba86 torrent: move torrentjsonstats to python3
This is an old python2 script. I had manually hacked it when I moved
torrent to rhel9, but a recent playbook run over everything put the old
python2 one back. So, lets fix it for once in ansible.

Signed-off-by: Kevin Fenzi <kevin@scrye.com>
2024-01-17 12:43:04 -08:00

37 lines
828 B
Python
Executable file

#!/usr/bin/python -tt
import sys
import simplejson
whitelist='/srv/torrent/btholding/whitelist'
if len(sys.argv) < 2:
print("Usage: torrentstats.py /path/to/torrent/stats/file")
sys.exit(1)
torrents = {}
for line in open(whitelist,'r').readlines():
line = line.strip()
csum, torrent = line.split('-', 1)
torrents[csum.strip()] = torrent.replace('.torrent','')
tlist = []
for line in open(sys.argv[1],'r').readlines():
line = line.strip()
if not line:
continue
tdict = {}
csum,total,active = line.split(':')
if csum not in torrents:
continue
tdict['name'] = torrents[csum].strip()
tdict['completed'] = int(total)
tdict['downloaders'] = int(active)
tdict['size'] = 0
tdict['seeds'] = 1
tlist.append(tdict)
print(simplejson.dumps(tlist))