-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_cache.py
More file actions
executable file
·59 lines (44 loc) · 1.38 KB
/
Copy pathbuild_cache.py
File metadata and controls
executable file
·59 lines (44 loc) · 1.38 KB
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
#! /usr/bin/env python
from iwi.core import classify
from iwi.core import Thread
from iwi.threading import Pool
from iwi.web import all_boards
from common import logger
from common import parameters
def build_cache (*links):
"""
Builds up the internal WebEntity.webcache with a snapshot of the provided
URLs.
If no URLs are given, it will attempt to update the cache with a snapshot
of the entirety of 4chan.
"""
pool = Pool(num_threads=parameters.num_threads)
def work (unit):
logger.info('working %r', unit)
if isinstance(unit, Thread):
unit.download()
else:
for e in unit.process():
pool.push(work, e)
if not links:
links = all_boards
for link in map(classify, links):
pool.push(work, link)
pool.join()
logger.info('Join complete.')
if __name__ == '__main__':
from common import CommonParser
parser = CommonParser (
description='Builds the web cache.',
epilog='if no links are given all of 4chan is scraped'
)
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)
build_cache(*args.link)
parser.post_process(args)