-
Notifications
You must be signed in to change notification settings - Fork 0
/
ics_handler.py
245 lines (179 loc) · 9.17 KB
/
ics_handler.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
import pyautogui
import pyperclip
import re
def locate_top_left(top_left_image_path):
top_left_location = pyautogui.locateOnScreen(top_left_image_path)
top_left_location = pyautogui.center(top_left_location)
return top_left_location
def keyboard_write(command: str, clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1, count: int = 1) -> None:
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
pyautogui.write(command, interval=interval)
keyboard_press(execute_press)
def keyboard_write_si(username: str, password: str, level: str, office: str, clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.3, count: int = 1):
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
pyautogui.write('si', interval=interval)
keyboard_press('f12', interval=interval, count=count)
pyautogui.write('%s/%s/%s/%s' % (username, password, level, office), interval=interval)
keyboard_press(execute_press)
def keyboard_write_so(clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1, count: int = 1):
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
pyautogui.write('so', interval=interval)
keyboard_press(execute_press)
def keyboard_write_ft(flt_num: str, flt_date: str, station: str = 'CAN', clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1, count: int = 1) -> None:
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
command = 'ft%s/%s/%s' % (flt_num, flt_date, station)
pyautogui.write(command, interval=interval)
keyboard_press(execute_press)
def keyboard_write_pd(flt_num: str, flt_date: str, *additions: str, cabin_class='', station: str = 'CAN', clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1, count: int = 1) -> None:
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
command = 'pd%s/%s' % (flt_num, flt_date)
if cabin_class:
command += cabin_class + '*'
else:
command += '*'
command += station
if additions:
for addition in additions:
command += ',' + addition
pyautogui.write(command, interval=interval)
keyboard_press(execute_press)
def keyboard_write_pr(count: int, clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1) -> None:
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
command = 'pr' + str(count) + 'pd'
pyautogui.write(command, interval=interval)
keyboard_press(execute_press)
def keyboard_write_fb(flt_num: str, flt_date: str, cabin_class, bn: str, station: str = 'CAN', clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1, count: int = 1) -> None:
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
command = 'pr%s/%s' % (flt_num, flt_date)
if cabin_class:
command += cabin_class + '*'
else:
command += '*'
command += station + ',' + 'bn' + bn
pyautogui.write(command, interval=interval)
keyboard_press(execute_press)
def keyboard_write_pn(count: int = 1, clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1) -> None:
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
command = 'pn' + str(count)
pyautogui.write(command, interval=interval)
keyboard_press(execute_press)
def keyboard_write_pl(count: int = 1, clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1) -> None:
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
command = 'pl' + str(count)
pyautogui.write(command, interval=interval)
keyboard_press(execute_press)
def keyboard_write_pf(count: int = 1, clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1) -> None:
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
command = 'pf' + str(count)
pyautogui.write(command, interval=interval)
keyboard_press(execute_press)
def keyboard_write_pu(*additions: str, clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1, count: int = 1) -> None:
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
command = 'pu' + str(count)
if additions:
for addition in additions:
command += ',' + addition
pyautogui.write(command, interval=interval)
keyboard_press(execute_press)
def keyboard_write_pre_pu(*additions: str, clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1, count: int = 1) -> None:
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
command = 'pu#' + str(count)
if additions:
for addition in additions:
command += ',' + addition
pyautogui.write(command, interval=interval)
keyboard_press(execute_press)
def keyboard_write_etkd(tkt_num: str, clean_screen_press: list = None, set_soe_press: str or list = 'esc', execute_press: str = 'f12', interval: float = 0.1) -> None:
keyboard_clean_screen(clean_screen_press)
keyboard_set_soe(set_soe_press)
command = 'etkd:tn/' + tkt_num
pyautogui.write(command, interval=interval)
keyboard_press(execute_press)
def keyboard_press(*keys: str, interval: float = 0.2, count: int = 1) -> None:
if len(keys) == 1:
pyautogui.press(keys[0], presses=count, interval=interval)
else:
pyautogui.press(list(keys), interval=interval)
def keyboard_key_up(key, interval: float = 0.2) -> None:
pyautogui.keyUp(key, interval=interval)
def keyboard_key_down(key, interval: float = 0.2) -> None:
pyautogui.keyDown(key, interval=interval)
def keyboard_hot_key(*keys: str, interval: float = 0.2) -> None:
eval('pyautogui.hotkey(%s, interval=%f)' % (str(keys)[1:-1], interval))
def keyboard_clean_screen(key_list: list = None, interval: float = 0.2) -> None:
if key_list is None:
key_list = ['ctrl', 'a']
if len(key_list) == 1:
keyboard_press(key_list[0], interval=interval)
else:
eval('pyautogui.hotkey(%s, interval=%f)' % (str(key_list)[1:-1], interval))
def keyboard_set_soe(key: str or list = None, interval: float = 0.3) -> None:
if type(key) is str:
keyboard_press(key, interval=interval)
elif type(key) is list:
eval('pyautogui.hotkey(%s, interval=%f)' % (str(key)[1:-1], interval))
# >>> pyautogui.moveTo(100, 100, 2, pyautogui.easeInQuad) # start slow, end fast
# >>> pyautogui.moveTo(100, 100, 2, pyautogui.easeOutQuad) # start fast, end slow
# >>> pyautogui.moveTo(100, 100, 2, pyautogui.easeInOutQuad) # start and end fast, slow in middle
# >>> pyautogui.moveTo(100, 100, 2, pyautogui.easeInBounce) # bounce at the end
# >>> pyautogui.moveTo(100, 100, 2, pyautogui.easeInElastic) # rubber band at the end
def mouse_move(x: int, y: int, duration: float = 0.1) -> None:
pyautogui.moveTo(x, y, duration=duration)
def mouse_drap(x: int, y: int, button: str = 'left', duration: float = 0.4) -> None:
pyautogui.dragTo(x, y, button=button, duration=duration, tween=pyautogui.easeOutQuad)
def mouse_click(button: str = 'left', clicks: int = 3, interval: float = 0.2):
pyautogui.click(button=button, clicks=clicks, interval=interval)
def mouse_up(button: str = 'left', x: int = None, y: int = None, duration: float = 0.2):
if x and y:
pyautogui.mouseUp(button=button, x=x, y=y, duration=duration)
else:
pyautogui.mouseUp(button=button, duration=duration)
def mouse_down(button: str = 'left', x: int = None, y: int = None, duration: float = 0.2):
if x and y:
pyautogui.mouseDown(button=button, x=x, y=y, duration=duration)
else:
pyautogui.mouseDown(button=button, duration=duration)
def mouse_scroll(clicks: int = 3, x: int = None, y: int = None, duration: float = 0.2):
if x and y:
pyautogui.mouseDown(clicks=clicks, x=x, y=y, duration=duration)
else:
pyautogui.mouseDown(clicks=clicks, duration=duration)
def mouse_position():
return pyautogui.position()
def text_copy():
keyboard_hot_key('ctrl', 'c')
def text_paste():
return pyperclip.paste()
def text_find_index(text):
index_list = re.findall(r'\d+\.', text)
if index_list:
return index_list[0][:-1], index_list[-1][:-1]
else:
return None
def text_has_flight(text):
if 'FLT NBR' in text or 'NEED INITIALIZE' in text:
return False
else:
return True
def text_has_ticket(text):
if 'GET TICKET FROM' in text:
return False
else:
return True
def text_has_number(text):
if 'PR: ' in text:
return True
else:
return False