-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessanger_group.py
301 lines (238 loc) · 9.55 KB
/
messanger_group.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import pandas as pd
import pyautogui as pg
import pyperclip
import time
from tkinter import filedialog, messagebox
import json
import time
import subprocess
moveGroup = lambda i : pg.moveTo(pg.center(group0Loc) + pg.Point(0, 60 * (i+3)))
search_menu_loc = school_loc = name_loc = search_button_loc = delete_name_loc = delete_school_loc = complete_loc = tab_start_loc = tab_end_loc = None
reject_list = []
def add(d, l, x):
if str(l[x+1]) == 'nan' or n-x-1 < 3:
if l[x] not in d:
d[l[x]] = [(l[-2], l[-1])]
else:
d[l[x]].append((l[-2], l[-1]))
return d
if l[x] in d:
d[l[x]] = add(d[l[x]], l, x+1)
else:
d[l[x]] = add({}, l, x+1)
return d
def dfs(d, depth):
if type(d) == list:
add_user(d, depth)
return
for i, key in enumerate(sorted(d.keys(), reverse=True)):
create_group(key, depth)
if i == 0:
moveGroup(depth)
pg.click()
dfs(d[key], depth+1)
def start_setting():
global group0Loc, menuLoc
settingData = {}
try:
with open('setting.json') as f:
settingData = json.load(f)
except:
with open('setting.json', 'w', encoding='utf-8') as f:
settingData['GOEMessengerPath'] = filedialog.askopenfilename(
initialdir="C:/Program Files (x86)/AtMessenger7",
title="GOE 메신저 선택",
filetypes=[("exe file", ".exe")]
)
json.dump(settingData, f, indent="\t")
subprocess.run(settingData['GOEMessengerPath'])
time.sleep(1)
menu_offLoc = pg.locateOnScreen('image/menu_off.png')
if menu_offLoc is not None:
pg.click(menu_offLoc)
menuLoc = pg.locateOnScreen('image/menu.png')
if menuLoc is None:
messagebox.showerror(title="세팅 오류", message="'내 목록' 메뉴를 선택해주세요.")
exit()
pg.moveTo(menuLoc)
pg.moveRel(60, 0)
pg.click()
pg.moveRel(-60, 0)
pg.click()
time.sleep(1)
downLocs = list(pg.locateAllOnScreen('image/drop_button_down.png'))
while downLocs:
for e in downLocs[::-1]:
pg.click(e)
downLocs = list(pg.locateAllOnScreen('image/drop_button_down.png'))
pg.moveTo(menuLoc)
pg.moveRel(60, 0)
pg.click()
pg.moveRel(-60, 0)
pg.click()
time.sleep(1)
group0Loc = pg.locateOnScreen('image/group_0.png')
moveGroup(-3)
pg.click(button='right')
pg.moveRel(50, 30)
pg.click()
pyperclip.copy("0 " + str(int(time.time())))
pg.hotkey('ctrl', 'v')
pg.press('enter')
moveGroup(-3)
pg.click(clicks=2, interval=1)
pg.moveTo(menuLoc)
pg.moveRel(60, 0)
pg.click()
pg.moveRel(-60, 0)
pg.click()
def create_group(name, depth):
moveGroup(depth)
pg.click(button='right')
pg.moveRel(60, 195)
pg.click()
pyperclip.copy(name)
pg.hotkey('ctrl', 'v')
pg.press('enter')
def add_user(l, depth):
global search_menu_loc, school_loc, name_loc, search_button_loc, delete_name_loc, delete_school_loc, complete_loc, tab_start_loc, tab_end_loc, reject_list, region0, region1
moveGroup(depth)
pg.click(button='right')
pg.moveRel(60, 220)
pg.click()
time.sleep(1)
if search_menu_loc is None:
search_menu_loc = pg.locateOnScreen('image/search_menu.png')
if search_menu_loc is None:
messagebox.showerror(title="사용자 추가 오류", message="'검색' 메뉴를 찾을 수 없습니다.")
exit()
if complete_loc is None:
complete_loc = pg.locateOnScreen('image/complete.png')
if complete_loc is None:
messagebox.showerror(title="사용자 추가 오류", message="'검색' 버튼을 찾을 수 없습니다.")
exit()
pg.moveTo(search_menu_loc)
pg.click()
if school_loc is None:
school_loc = pg.locateOnScreen('image/school.png')
if school_loc is None:
messagebox.showerror(title="사용자 추가 오류", message="'소속' 입력 창을 찾을 수 없습니다.")
exit()
if name_loc is None:
name_loc = pg.locateOnScreen('image/name.png')
if name_loc is None:
messagebox.showerror(title="사용자 추가 오류", message="'검색어 입력' 입력 창을 찾을 수 없습니다.")
exit()
if search_button_loc is None:
search_button_loc = pg.locateOnScreen('image/search_button.png')
if search_button_loc is None:
messagebox.showerror(title="사용자 추가 오류", message="'검색' 버튼을 찾을 수 없습니다.")
exit()
pg.moveTo(school_loc)
pg.click()
pg.typewrite('.')
pg.moveTo(name_loc)
pg.click()
pg.typewrite('.')
if tab_start_loc is None:
tab_start_loc = pg.locateCenterOnScreen('image/add_tab_start.png')
if tab_start_loc is None:
messagebox.showerror(title="사용자 추가 오류", message="GOE 메신저 창 (좌상단)을 찾을 수 없습니다.")
exit()
tab_end_loc = pg.locateCenterOnScreen('image/add_tab_end.png')
if tab_end_loc is None:
messagebox.showerror(title="사용자 추가 오류", message="GOE 메신저 창 (우하단)을 찾을 수 없습니다.")
exit()
region1 = region0 = (tab_start_loc.x, tab_start_loc.y, tab_end_loc.x - tab_start_loc.x, tab_end_loc.y - tab_start_loc.y)
pg.click(search_button_loc)
not_user_loc = pg.locateOnScreen('image/not_user.png', region=region0)
while not_user_loc is None:
not_user_loc = pg.locateOnScreen('image/not_user.png', region=region0)
region0 = tuple(not_user_loc)
pg.click(not_user_loc)
pg.moveRel(0, 100)
pg.click()
if delete_school_loc is None:
delete_school_loc, delete_name_loc = pg.locateAllOnScreen('image/delete.png')
if delete_school_loc is None:
messagebox.showerror(title="사용자 추가 오류", message="'삭제' 버튼을 찾을 수 없습니다.")
exit()
for school, name in l:
pg.click(delete_school_loc)
pyperclip.copy(school)
pg.hotkey('ctrl', 'v')
pg.click(delete_name_loc)
pyperclip.copy(name)
pg.hotkey('ctrl', 'v')
pg.click(search_button_loc)
not_user_loc = pg.locateOnScreen('image/not_user.png', region=region0)
user_loc = pg.locateOnScreen('image/user.png', region=region1)
while not_user_loc is None and user_loc is None:
not_user_loc = pg.locateOnScreen('image/not_user.png', region=region0)
user_loc = pg.locateOnScreen('image/user.png', region=region1)
if not_user_loc is not None:
region0 = tuple(not_user_loc)
pg.click(not_user_loc)
reject_list.append((school, name))
else:
region1 = tuple(user_loc)
pg.moveRel(-40, 44)
pg.click(button='right')
pg.moveTo(complete_loc)
pg.click()
def validate(l):
pg.click()
for school, name in l:
pg.moveTo(delete_school_loc)
pg.click()
pyperclip.copy(school)
pg.hotkey('ctrl', 'v')
pg.moveTo(delete_name_loc)
pg.click()
pyperclip.copy(name)
pg.hotkey('ctrl', 'v')
pg.moveTo(search_button_loc)
pg.click()
time.sleep(2)
pg.moveRel(-40, 44)
pg.click(button='right')
time.sleep(0.1)
if __name__=='__main__':
start_time0 = time.time()
inputPath = filedialog.askopenfilename(
initialdir=".",
title="엑셀 파일 선택",
filetypes=[("Excel files", ".xlsx .xls")]
)
try:
df = pd.read_excel(inputPath, sheet_name = 'input')
except:
messagebox.showerror(title="엑셀 파일 오류", message="제대로 된 엑셀 파일을 지정해주세요.")
exit()
start_setting()
l = df.values.tolist()
unit = len(l)
n = len(l[0])
d = {}
for line in l:
add(d, line, 0)
start_time1 = time.time()
dfs(d, 0)
print("[ 검색 이상자 목록 ]")
print('소속\t이름')
for school, name in reject_list:
print(school, name, sep='\t')
print("총 인원 :", len(l))
print("승인 인원 :", len(l) - len(reject_list))
print("이상 인원 :", len(reject_list))
print("이상자 비율 : ", (len(reject_list) / len(l)) * 100, "%", sep='')
print()
print("[ 실행 시간 분석 ]")
print("Total time (sec) : "+ str(time.time() - start_time0))
print("Setting time (sec) : "+ str(start_time1 - start_time0))
print("Automation time (sec) : "+ str(time.time() - start_time1))
print("Unit : "+ str(unit))
print("Unit per second (Total) : "+ str(unit /(time.time() - start_time0)))
print("Unit per second (Automation) : "+ str(unit /(time.time() - start_time1)))
print("Second per Unit (Total) : "+ str((time.time() - start_time0)/unit))
print("Second per Unit (Automation) : "+ str((time.time() - start_time1)/unit))