-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion_2.py
131 lines (105 loc) · 3.6 KB
/
version_2.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
124
125
126
127
128
129
130
131
import time
import os
from InfoWindow import InfoWindow
from Interact import Interact
from Telebot import Telebot
from ImageAnalyzer import ImageAnalyzer
class EbookCrawler:
_root_path = "~/Downloads/screenshots/"
_check_name_dup = False
_name_list = []
_is_pdf = []
_current_name = ""
_tele = None
_testing = None
_time_per_page = 0.6
def __init__(self):
self._name_list, self._testing, self._is_pdf, self._time_per_page = (
InfoWindow.loop()
)
if self._name_list.__len__() == 0:
print("No data entered!")
exit(9)
if self._testing:
print("-------Testing mode-------")
print(self._name_list)
if self.check_dup_in_namelist(self._name_list):
print("Duplicate names entered!")
exit(9)
for name in self._name_list:
self.check_dup_in_path(name)
if self._check_name_dup:
print("choose another name!")
exit(9)
self._tele = Telebot()
def check_dup_in_namelist(self, lst):
return len(lst) != len(set(lst))
def check_dup_in_path(self, name, create=False):
temp_path = self._root_path + name
real_path = os.path.expanduser(temp_path)
print(real_path)
if os.path.exists(real_path):
print("File '{}' already exists!".format(name))
self._check_name_dup = True
elif create:
os.mkdir(real_path)
return real_path
def clean_up(self):
self._tele.send_message("all done - " + self._name_list.__str__())
Interact.rotate_screen()
def start_capture(self, name, index):
self._current_name = name
save_path = ""
if not self._testing:
save_path = self.check_dup_in_path(name, True)
page = 1
Interact.click_item(index)
if not self._testing:
time.sleep(7)
else:
time.sleep(3)
while True:
screenshot = Interact.get_screenshot()
if not self._testing:
screenshot.save("{}/{}_{}.png".format(save_path, name, page))
Interact.move_to_next_page()
if ImageAnalyzer.is_last_page(screenshot):
Interact.click_exit()
print("{} - Page: {}".format(name, page - 1))
self._tele.send_message(
"({}/{}) - {} - p.{}".format(
index, self._name_list.__len__(), name, page - 1
)
)
time.sleep(5)
break
if ImageAnalyzer.is_same_page_as_before(screenshot):
print("Stop Error: {} - Page: {}".format(name, page))
self._tele.send_error("Stop Error: {} - Page: {}".format(name, page))
break
time.sleep(0.6)
page += 1
def run(self):
try:
self._tele.send_message("start - " + self._name_list.__str__())
if not self._testing:
time.sleep(5)
else:
time.sleep(2)
for index, name in enumerate(self._name_list, start=1):
print("\n----", name)
self.start_capture(name, index)
self.clean_up()
except Exception as e:
print("--- Exception Error ---")
print(e)
self._tele.send_message(self._current_name, True)
self._tele.send_error(e)
exit(9)
finally:
exit(0)
def main():
app = EbookCrawler()
app.run()
if __name__ == "__main__":
main()