-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrack.py
executable file
·79 lines (59 loc) · 1.91 KB
/
crack.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /usr/bin/env python
from iwi.collections import SortedSet
from iwi.core import classify
from iwi.core import Post
from iwi.solving import SQLSolver
from iwi.threading import Pool
from common import logger
from common import parameters
def crack (*links):
"""
Returns a list of Posts with cracked trips.
Reads 4chan URLs, scrapes contents and attempts to crack the tripcodes
found. If any posts were cracked the corresponding Post object is added to
a list that is returned.
The list is sorted by time of post.
"""
posts = SortedSet()
pool = Pool(num_threads=parameters.num_threads)
pub_solver = SQLSolver(parameters.public_file)
sec_solver = SQLSolver(parameters.secure_file)
def work (unit):
if isinstance(unit, Post):
if unit.public or unit.secure:
return unit
return
logger.info('working %r', unit)
for e in unit.process():
pool.push(work, e)
for link in map(classify, links):
pool.push(work, link)
pool.join()
logger.info('Join complete, updating with results.')
posts.update(pool.get_results())
pool.close()
solved = []
for e in sorted(posts, key = lambda post : post.time):
if e.public:
e.public.solve(pub_solver)
if e.secure:
e.secure.solve(sec_solver)
if e.solved():
solved.append(e)
return solved
if __name__ == '__main__':
from common import TripcodeParser
parser = TripcodeParser (
description='Looks for tripcodes and cracks them.'
)
parser.add_argument (
'link', nargs='+',
help='boards/pages/threads, may either be full URLs or names like /g/'
)
args = parser.parse_args()
if parser.sanity_check(args):
exit(1)
parser.pre_process(args)
for e in crack(*args.link):
print e
parser.post_process(args)