-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmp_tc_diff.py
369 lines (338 loc) · 15.4 KB
/
tmp_tc_diff.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import pandas as pd
import os
pd.options.display.max_columns = None
pd.options.display.max_rows = None
from datetime import datetime, timedelta, date
import sys
import warnings
warnings.filterwarnings('ignore')
from appium import webdriver as appium_webdriver
from selenium import webdriver as selenium_webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import re
import time
import shutil
tc_short_action, arrival_time_action, arrival_time_action_new = 1, 0, 1
tc_short_check_start, tc_short_check_end = 0, 0
arrival_time_start, arrival_time_end = 0, 0
def get_verification_code():
server = 'http://localhost:4723/wd/hub'
desired_caps = {
"platformName": "Android",
"deviceName": "KB2000",
"appPackage": "com.oneplus.mms",
"appActivity": "com.android.mms.ui.ConversationList",
"noReset": True,
"automationName": "UIAutomator2"
}
driver = appium_webdriver.Remote(server, desired_caps)
wait = WebDriverWait(driver, 30)
verification_texts = wait.until(EC.presence_of_all_elements_located((By.ID, 'com.oneplus.mms:id/conversation_snippet')))
for item in verification_texts:
verification_text = item.get_attribute('text')
verification_code = re.search('\d{6}', verification_text).group(0)
if '【十荟团】' in verification_text:
return verification_code
break
def find_element_by_clickable(item):
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, item)))
return element
def find_element_by_presence(item):
element = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, item)))
return element
def find_elements_by_presence(item):
elements = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, item)))
return elements
def date_select(date_start, date_end):
date_panel_left_head_text = find_element_by_presence(
'div.el-date-range-picker__content.is-left div.el-date-range-picker__header').text
date_panel_left_head_text_month = int(re.search('(.*?) 年 (.*?) 月', date_panel_left_head_text).group(2))
print(date_panel_left_head_text_month)
date_panel_left_forward = find_element_by_presence(
'div.el-date-range-picker__content.is-left div.el-date-range-picker__header button.el-icon-arrow-left')
date_panel_left_back = find_element_by_presence(
'div.el-date-range-picker__content.is-right div.el-date-range-picker__header button.el-icon-arrow-right')
if date_start.month < date_panel_left_head_text_month:
date_panel_left_forward.click()
date_panel_left_table = find_elements_by_presence(
'div.el-date-range-picker__content.is-left table td.available')
for item in date_panel_left_table:
if int(item.text) == date_start.day:
item.click()
break
date_panel_left_back.click()
elif date_start.month == date_panel_left_head_text_month:
date_panel_left_table = find_elements_by_presence(
'div.el-date-range-picker__content.is-left table td.available')
for item in date_panel_left_table:
if int(item.text) == date_start.day:
item.click()
break
else:
print('date_start_error')
sys.exit(0)
if date_end.month == date_panel_left_head_text_month:
date_panel_left_table = find_elements_by_presence(
'div.el-date-range-picker__content.is-left table td.available')
for item in date_panel_left_table:
if int(item.text) == date_end.day:
item.click()
break
elif date_end.month > date_panel_left_head_text_month:
date_panel_left_table = find_elements_by_presence(
'div.el-date-range-picker__content.is-left table td.next-month')
for item in date_panel_left_table:
if int(item.text) == date_end.day:
item.click()
break
elif date_end.month < date_panel_left_head_text_month:
date_panel_left_forward.click()
date_panel_left_table = find_elements_by_presence(
'div.el-date-range-picker__content.is-left table td.available')
for item in date_panel_left_table:
if int(item.text) == date_end.day:
item.click()
break
# date_panel_left_back.click()
else:
print('date_end_error')
sys.exit(0)
if tc_short_action == 1:
browser = selenium_webdriver.Chrome()
browser.get('https://wms.nicetuan.net/login')
wait = WebDriverWait(browser, 20)
user = find_element_by_presence('input.input_all.name').send_keys('')
code_button = find_element_by_clickable('button#code').click()
verification_code = get_verification_code()
print(verification_code)
password = find_element_by_presence('input.input_all_code.password').send_keys(verification_code)
warehouse_select = find_element_by_clickable('a.textbox-icon.combo-arrow').click()
warehouse = find_element_by_clickable('div#_easyui_combobox_i1_4').click()
login = find_element_by_clickable('a#login.button.hide').click()
# 20210604
time.sleep(1)
panel_headers = find_elements_by_presence('div.panel-title.panel-with-icon')
for item in panel_headers:
if '提示' in item.text:
close = find_elements_by_presence('a.panel-tool-close')[1].click()
break
time.sleep(1)
stock_mangement = find_element_by_clickable('div.accordion-header-selected').click()
warehouse_mangement = find_element_by_clickable('div.panel-last').click()
for items in [
# ('hanzhou', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(2)'),
# ('wenzhou', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(3)'),
('jiangsu', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(1)'),
# ('xuzhou', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(5)'),
# ('hefei', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(6)'),
]:
lvyuezhongxin = find_element_by_clickable('div#_easyui_tree_19 span.tree-title').click()
browser.switch_to.window(browser.window_handles[1])
tc_mangement = find_element_by_clickable('ul[role="menubar"] span:nth-child(8) > li').click()
tc_short_check = find_element_by_clickable(
'ul[role="menubar"] span:nth-child(8) > li li.el-menu-item:nth-child(4)').click()
station_button = find_element_by_clickable('div.el-form-item--small:nth-child(1) div.el-form-item__content').click()
time.sleep(1)
station_select = find_element_by_clickable(items[1])
print(station_select.text)
station_select.click()
date_button = find_element_by_presence('i.el-range__icon').click()
time.sleep(1)
date_start = date.today() - timedelta(days=tc_short_check_start)
date_end = date.today() - timedelta(days=tc_short_check_end)
print(date_start, date_end)
date_select(date_start, date_end)
search_button = find_element_by_clickable('button.el-icon-search').click()
while True:
data_table = find_element_by_presence('div.el-table__body-wrapper')
if data_table.text != '暂无数据':
break
time.sleep(1)
downnload_button = find_element_by_clickable('button.el-icon-download').click()
download_path = r'C:\Users\aesdhj\Downloads'
destination_path = r'C:\Users\aesdhj\Desktop'
while True:
i = 0
file_list = os.listdir(download_path)
for file in file_list:
if ('服务站差异' in file) and ('crdownload' not in file):
download_file_path = os.path.join(download_path, file)
destination_file_path = os.path.join(destination_path, '服务站差异{}.xlsx'.format(items[0]))
shutil.move(download_file_path, destination_file_path)
i += 1
if i > 0:
break
time.sleep(1)
time.sleep(1)
browser.close()
browser.switch_to.window(browser.window_handles[0])
browser.quit()
else:
pass
time.sleep(1)
if arrival_time_action == 1:
browser = selenium_webdriver.Chrome()
browser.get('https://wms.nicetuan.net/login')
wait = WebDriverWait(browser, 20)
user = find_element_by_presence('input.input_all.name').send_keys('')
code_button = find_element_by_clickable('button#code').click()
verification_code = get_verification_code()
print(verification_code)
password = find_element_by_presence('input.input_all_code.password').send_keys(verification_code)
warehouse_select = find_element_by_clickable('a.textbox-icon.combo-arrow').click()
warehouse = find_element_by_clickable('div#_easyui_combobox_i1_4').click()
login = find_element_by_clickable('a#login.button.hide').click()
# 20210604
time.sleep(1)
panel_headers = find_elements_by_presence('div.panel-title.panel-with-icon')
for item in panel_headers:
if '提示' in item.text:
close = find_elements_by_presence('a.panel-tool-close')[1].click()
break
time.sleep(1)
stock_mangement = find_element_by_clickable('div.accordion-header-selected').click()
warehouse_mangement = find_element_by_clickable('div.panel-last').click()
for items in [
('hanzhou', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(2)'),
('wenzhou', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(3)'),
('jiangsu', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(4)'),
('xuzhou', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(5)'),
('hefei', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(6)'),
]:
lvyuezhongxin = find_element_by_clickable('div#_easyui_tree_19 span.tree-title').click()
browser.switch_to.window(browser.window_handles[1])
tc_mangement = find_element_by_clickable('ul[role="menubar"] span:nth-child(8) > li').click()
tc_arrival_time = find_element_by_clickable(
'ul[role="menubar"] span:nth-child(8) > li li.el-menu-item:nth-child(6)').click()
station_button = find_element_by_clickable('div.el-input--suffix:nth-child(1)').click()
station_select = find_element_by_clickable(items[1])
print(station_select.text)
station_select.click()
date_button = find_elements_by_presence('i.el-range__icon')[0].click()
time.sleep(1)
date_start = date.today() - timedelta(days=arrival_time_start)
date_end = date.today() - timedelta(days=arrival_time_end)
print(date_start, date_end)
date_select(date_start, date_end)
search_button = find_element_by_clickable('button.el-icon-search').click()
while True:
data_table = find_element_by_presence('div.el-table__body-wrapper')
if data_table != '暂无数据':
break
time.sleep(1)
downnload_button = find_element_by_clickable('button.el-icon-download').click()
download_path = r'C:\Users\aesdhj\Downloads'
destination_path = r'C:\Users\aesdhj\Desktop'
while True:
i = 0
file_list = os.listdir(download_path)
for file in file_list:
if ('服务站支线' in file) and ('crdownload' not in file):
download_file_path = os.path.join(download_path, file)
destination_file_path = os.path.join(destination_path, '服务站支线{}.xlsx'.format(items[0]))
shutil.move(download_file_path, destination_file_path)
i += 1
if i > 0:
break
time.sleep(1)
time.sleep(1)
browser.close()
browser.switch_to.window(browser.window_handles[0])
browser.quit()
else:
pass
if arrival_time_action_new == 1:
browser = selenium_webdriver.Chrome()
browser.get('https://wms.nicetuan.net/login')
wait = WebDriverWait(browser, 20)
user = find_element_by_presence('input.input_all.name').send_keys('13770995264')
code_button = find_element_by_clickable('button#code').click()
verification_code = get_verification_code()
print(verification_code)
password = find_element_by_presence('input.input_all_code.password').send_keys(verification_code)
time.sleep(1)
warehouse_select = find_element_by_clickable('a.textbox-icon.combo-arrow').click()
warehouse = find_element_by_clickable('div#_easyui_combobox_i1_4').click()
login = find_element_by_clickable('a#login.button.hide').click()
# 20210604
time.sleep(1)
panel_headers = find_elements_by_presence('div.panel.window.panel-htop')
for item in panel_headers:
if '提示' in item.text:
close = item.find_element_by_css_selector('a.panel-tool-close').click()
time.sleep(1)
stock_mangement = find_element_by_clickable('div.accordion-header-selected').click()
warehouse_mangement = find_element_by_clickable('div.panel-last').click()
for items in [
# ('hanzhou', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(2)'),
# ('wenzhou', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(3)'),
('jiangsu', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(4)'),
# ('xuzhou', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(5)'),
# ('hefei', 'div[x-placement="bottom-start"] li.el-select-dropdown__item:nth-child(6)'),
]:
tms_center = find_element_by_clickable('div#_easyui_tree_20 span.tree-title').click()
browser.switch_to.window(browser.window_handles[1])
for item in find_elements_by_presence('ul.sideBox li'):
if '支线管理' in item.text:
item.click()
time.sleep(1)
dispatch_task_report = item.find_element_by_css_selector('ul[role="menu"] li:nth-child(1)').click()
time.sleep(1)
break
warehouse_button = find_element_by_clickable('div.el-row--flex div.el-form-item--small:nth-child(1) span.el-input__suffix').click()
warehouse_select = find_element_by_clickable(items[1])
print(warehouse_select.text)
warehouse_select.click()
date_button = find_elements_by_presence('i.el-range__icon')[0].click()
time.sleep(1)
date_start = date.today() - timedelta(days=arrival_time_start)
date_end = date.today() - timedelta(days=arrival_time_end)
print(date_start, date_end)
date_select(date_start, date_end)
search_button = find_element_by_clickable('button.el-button.el-icon-search').click()
time.sleep(2)
download_button = find_element_by_clickable('button.el-button.el-icon-download').click()
comfirmed_tag = find_element_by_presence('div.el-message-box__container')
if comfirmed_tag.text == '导出成功!':
comfirmed_button = find_element_by_clickable('button.el-button--default').click()
time.sleep(2)
for item in find_elements_by_presence('ul.sideBox li'):
if '下载管理' in item.text:
download_mangement = item.find_element_by_css_selector('a[href="#/download"]').click()
break
download = find_element_by_presence('tr.el-table__row:nth-child(1)')
while True:
download_status = download.find_element_by_css_selector('td:nth-child(3)')
if download_status.text == '完成':
download_access = download.find_element_by_css_selector('td:nth-child(5) a')
download_url = download_access.get_attribute('href')
browser.execute_script('window.open()')
browser.switch_to.window(browser.window_handles[2])
# ActionChains(browser).move_to_element(download_access).click(download_access).perform()
browser.get(download_url)
break
time.sleep(2)
download_path = r'C:\Users\aesdhj\Downloads'
destination_path = r'C:\Users\aesdhj\Desktop'
while True:
i = 0
file_list = os.listdir(download_path)
for file in file_list:
if ('branch' in file) and ('crdownload' not in file):
download_file_path = os.path.join(download_path, file)
destination_file_path = os.path.join(destination_path, '服务站支线{}.xlsx'.format(items[0]))
shutil.move(download_file_path, destination_file_path)
i += 1
if i > 0:
break
time.sleep(1)
browser.close()
browser.switch_to.window(browser.window_handles[1])
browser.close()
browser.switch_to.window(browser.window_handles[0])
browser.quit()
else:
pass
sys.exit(0)