-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathallchan.py
55 lines (46 loc) · 1.54 KB
/
allchan.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
#!/usr/bin/env python3
#
# Author: Kahsolt
# Description: Image crawler for xChan.
# Create Date: 2018/11/24
# Update Date: 2018/11/30
#
import sys
from allchan import Watcher
from allchan import Downloader
from allchan.setting import DOWNLOAD_WORKER
if __name__ == '__main__':
if len(sys.argv) == 1:
print('[Allchan] started in watch mode')
watcher = Watcher()
try:
watcher.start()
while True:
url = input('>> Add watch thread url:\n').strip(' \t\n\r')
if len(url) > 0:
try:
watcher.add_watched_thread(url)
print('<< [OK] thread %r added to watchlist' % url)
except:
print('<< [ERROR] bad url!!')
except KeyboardInterrupt:
watcher.stop()
elif len(sys.argv) == 2:
arg = sys.argv[1]
if arg == '-sync':
print('[Allchan] started in sync mode')
downloader = Downloader(DOWNLOAD_WORKER)
try:
downloader.start()
downloader.wait()
except KeyboardInterrupt:
downloader.stop()
elif arg == '-update':
print('[Allchan] started in instant update mode')
watcher = Watcher()
try:
watcher.instant_update()
except KeyboardInterrupt:
watcher.db.flush()
else:
print('Usage: allchan [-sync|-update]')