-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomic_reader.py
79 lines (63 loc) · 2.08 KB
/
comic_reader.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
import sys
from downloader import Downloader
from viewer import Viewer
import yaml
import os
"""
Advertisementless comic reader
AT
20191223
usage:
comic_reader.py
-d
--domain <domain specifically for images (i.whatever.net)>
-p
--path <path after domain (/galleries/)>
-n
--number <comic number>
-c
--config <config_file_location/config_file_name.yaml>
"""
def parseargs(cmds):
"""
simple sysargv parsing
:param cmds: args when called
:return: list of relevant args
"""
if len(cmds) < 2:
return pull_from_config()
domain = ""
path = ""
number = ""
ltr = False
for i in range (0, len(cmds)-1):
if cmds[i] == "-d" or cmds[i] == "--domain":
domain = cmds[i+1]
if cmds[i] == "-p" or cmds[i] == "--path":
path = cmds[i+1]
if cmds[i] == "-n" or cmds[i] == "--number":
number = str(cmds[i+1])
if cmds[i] == "-c" or cmds[i] == "--config":
return pull_from_config(cmds[i+1])
return {"domain": domain, "path": path, "number": number}
def pull_from_config(file_location="config.yaml"):
if os.path.isfile(file_location):
with open(file_location) as file:
result = yaml.load(file, Loader=yaml.FullLoader)
if result == "{'domain': '', path: '', number: ''}" or result is None:
print("Config file improperly configured or empty. For future use, add a valid Config.yaml or use arguments.")
return make_fast_config()
return result
else:
print("Missing config file. For future use, add a valid Config.yaml or use arguments.")
return make_fast_config()
def make_fast_config():
print("Enter a link to a comic (minus the image itself)")
link = input("i.e. i.comics.com/comicname/comicnumber/1.jpg becomes i.comics.com/comicname/comicnumber/ \n")
return {'domain': link, 'path': '', 'number': ''}
def main():
downloader = Downloader(parseargs(sys.argv))
downloader.download()
viewer = Viewer(downloader.page_arr, 400)
viewer.start()
main()