-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
123 lines (114 loc) · 3.01 KB
/
main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import json
import re
import sys
import time
import collector
import helpers
def archive(args, options):
c = collector.Collector(
options=options,
dry_run=args.dry,
clean=args.clean,
parallel=args.parallel,
reverse=args.reverse,
start_from=args.start,
use_proxies=args.use_proxies,
)
c.pack_collections()
c.clean()
c.close()
def collect(args, options):
c = collector.Collector(
options=options,
dry_run=args.dry,
clean=args.clean,
parallel=args.parallel,
reverse=args.reverse,
start_from=args.start,
use_proxies=args.use_proxies,
)
try:
c.collect()
except Exception as e:
print("!!! Exception occured:", e)
time.sleep(2)
c.clean()
c.close()
c.pack_collections()
c.clean()
# c.close()
def main(args):
if not helpers.url_validator(args):
print("= ERROR: URL is not valid. Please provide a valid URL. Exiting...")
sys.exit(1)
# only archive
if args.archive:
archive(args, None)
return
if args.json is None:
print("= No configuration given")
parser.print_help()
return
with open(args.json) as json_file:
options = json.load(json_file)
# collect
collect(args, options)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Creates a comic reader compatible file from a given URL",
epilog="Run as: python main.py -v -c -j default_config.json"
)
parser.add_argument(
"-a",
"--archive",
help="archive the folders of collected images",
dest="archive",
action="store_true",
)
parser.add_argument(
"-u", "--url", type=str, metavar="url", help="URL to scrape chapters from"
)
parser.add_argument(
"-j", "--json", type=str, metavar="json", help="Path config json"
)
parser.add_argument(
"-c", "--clean", help="keep only .cbz files", dest="clean", action="store_true"
)
parser.add_argument(
"-p",
"--parallel",
help="parallel execution",
dest="parallel",
action="store_true",
)
parser.add_argument(
"-d",
"--dry-run",
help="only print what you will do",
dest="dry",
action="store_true",
)
parser.add_argument(
"-r",
"--reverse",
help="reverse execution on chapters",
dest="reverse",
action="store_true",
)
parser.add_argument(
"-v", "--verbose", help="verbose execution", dest="verbose", action="store_true"
)
parser.add_argument(
"-s", "--start", type=int, metavar="start", help="starts from chapter (included)"
)
parser.add_argument(
"-n",
"--no-proxies",
help="starts from this chapter",
dest="use_proxies",
action="store_false",
)
main(parser.parse_args())