forked from iw00t/REDBetter
-
Notifications
You must be signed in to change notification settings - Fork 3
/
torrent-parse.py
54 lines (41 loc) · 1.37 KB
/
torrent-parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python2.7
# make me a conjob!
import os
import json
import argparse
import ConfigParser
import sys
lockfile = os.path.expanduser('~/.redactedbetter/parse.lock')
def main():
if os.path.exists(lockfile):
print "Found lockfile, exiting...."
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog='redactedbetter')
parser.add_argument('--cache', help='the location of the cache',
default=os.path.expanduser('~/.redactedbetter/cache-crawl'))
args = parser.parse_args()
while parse_stuff(args.cache) and not os.path.exists(lockfile):
print "Done encoding cycle"
def parse_stuff(cache_file):
open(lockfile, 'w').close()
try:
cache = json.load(open(cache_file))
except:
cache = []
json.dump(cache, open(cache_file, 'wb'))
permalinks = []
cache_new = []
for torrent in cache:
if torrent['done']:
permalinks.append('"https://redacted.ch/%s"' % torrent['permalink'])
else:
cache_new.append(torrent)
if len(permalinks) == 0:
return False
cmdline = "python2 redactedbetter %s" % ' '.join(permalinks)
json.dump(cache_new, open(cache_file, 'wb'))
print "Executing... " + cmdline
os.system(cmdline)
os.remove(lockfile)
return True
if __name__ == '__main__':
main()