-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
159 lines (123 loc) · 4 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import MessageHandler.Input as input
import MessageHandler.Output as output
import WindowsHandler.FindBooks as findBooks
import WindowsHandler.DetailViewHandler as detailHandler
import WebCrawling.WebCrawling as WebCrawling
import os
import sys
import time
import pyautogui
import pyperclip
import win32clipboard
## 파일 포인터 전역변수로 선언
global fp
def isValidRange(start, end) :
if int(start) > int(end) :
output.sendAlertMessage("끝번호가 시작번호보다 작습니다.\n다시 입력하세요.")
return False
return True
def pushNextButton() :
region = (start_x + w_width//2, start_y + 30, w_width, w_height)
pyautogui.click(pyautogui.locateOnScreen("C:/Program Files (x86)/Sejong Library Automation/asset/nextButton.png"))
def checkLastBook() :
if pyautogui.locateOnScreen("C:/Program Files (x86)/Sejong Library Automation/asset/nextButton_grayscale.png") :
output.sendAlertMessage("끝났습니다!")
fp.close()
browser.quit()
sys.exit()
return
########################
"""
if sys.argv[-1] != 'asadmin':
script = os.path.abspath(sys.argv[0])
params = ' '.join([script] + sys.argv[1:] + ['asadmin'])
shell.ShellExecuteEx(lpVerb='runas', lpFile=sys.executable, lpParameters=params)
sys.exit(0)
"""
startNumber = 0
endNumber = 0
registNumberString = "" #등록번호 입력에 쓰일 문자열
#########################main start point
#창 활성화 확인
w = pyautogui.getWindowsWithTitle("통합작업환경")
if len(w) == 0 :
output.sendAlertMessage("통합작업환경(IWS)를 열고 실행해주세요.")
sys.exit()
ww = pyautogui.getWindowsWithTitle("통합작업환경")[0]
#파일 open
fp = open("./not_inserted_ISBN.txt", "w")
#등록번호 입력
while True :
startNumber = input.getStartRegistNumber()
if startNumber is None :
sys.exit()
endNumber = input.getEndRegistNumber()
if endNumber is None :
sys.exit()
if isValidRange(startNumber[6:12], endNumber[6:12]) :
break
#등록번호 확인
registNumberString = str(startNumber) + " ~ " + str(endNumber)
if output.confirmBeforeTheRunning(registNumberString) == "Cancel" :
sys.exit()
#등록번호 검색
findBooks.putsRegistNumber(registNumberString)
#체크박스 선택
time.sleep(2)
findBooks.selectCheckBox(int(endNumber) - int(startNumber))
#상세보기 진입
pyautogui.move(200, 0)
pyautogui.rightClick()
time.sleep(0.3)
pyautogui.rightClick()
time.sleep(0.3)
pyautogui.press("down")
pyautogui.press("enter")
#창크기 추출
w_width = w[0].size.width
w_height = w[0].size.height
start_x = w[0].left
start_y = w[0].top
print(start_x, w_width)
print(start_y, w_height)
#관계정보 탭 선택 (1회)
time.sleep(1.5)
detailHandler.selectRelationTab(w)
#저장시스템
count = int(endNumber) - int(startNumber) + 1
now_count = 0
center_x = w[0].center.x
center_y = w[0].center.y
browser = WebCrawling.initBrowser()
while now_count < count :
now_count += 1
#이미 초록목차가 작성된 책인지 확인
if detailHandler.checkAlreadyHave(w) :
checkLastBook()
pushNextButton()
continue
#ISBN 추출
pyautogui.click(center_x+100, center_y, clicks=2, interval=0.2)
pyautogui.hotkey("ctrl", "a")
pyautogui.hotkey("ctrl", "c")
win32clipboard.OpenClipboard()
isbn = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
index = isbn.find("▼a")
index+=2
isbn = isbn[index : index + 13]
#초록목차 크롤링
bookInfo = WebCrawling.getData(browser, isbn);
if bookInfo is None:
fp.write(str(isbn) + "\n")
checkLastBook()
pushNextButton()
continue
bookIntro, tableContent = bookInfo[0], bookInfo[1]
#초록목차 저장
detailHandler.saveInformation(bookIntro, tableContent, w)
#버튼 비활성화 되면 끝남.
checkLastBook()
pushNextButton()
output.sendAlertMessage("끝났습니다!")
browser.quit()