Unify export-task matching to time tolerance only (≤40s)

去掉顺心/中通/韵达/安能(应到) 导出任务认领时的标题/模块名校验,
统一改为仅按提交时间容差 ≤40 秒匹配本批任务。

理由:单账号无并发,时间窗内的任务必为本批所建;而站点可能调整
任务标题名,写死标题会导致匹配失败、任务已创建却一直查不到。
同步清理因此变成死代码的局部变量与函数形参。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-07-06 22:04:22 +08:00
parent d05848ee36
commit 63ee8bbae1
4 changed files with 83 additions and 113 deletions

View File

@@ -49,7 +49,6 @@ def zto_smart_menu_click(page, menu_path):
def zto_expected_download(page):
"""中通:应到货物数据下载"""
print("\n▶ 开始执行【中通 - 应到货物数据下载】任务...")
target_task_title = "进站交接单查询-运单信息"
download_dir = DOWNLOAD_DIR
if not os.path.exists(download_dir):
@@ -245,7 +244,6 @@ def zto_expected_download(page):
_zto_poll_and_download_tasks(
page,
export_times,
target_task_title,
download_dir,
"中通-应到货物数据.xlsx",
)
@@ -258,7 +256,6 @@ def zto_expected_download(page):
def zto_actual_download(page):
"""中通:实到货物数据下载"""
print("\n▶ 开始执行【中通 - 实到货物数据下载】任务...")
target_task_title = "到件扫描管理"
download_dir = DOWNLOAD_DIR
if not os.path.exists(download_dir):
@@ -340,9 +337,7 @@ def zto_actual_download(page):
"没有搜索到符合条件的数据记录"
)
if empty_flag.is_visible():
print(
" ⚠️ 当前查询范围内没有数据,终止并关闭标签页。"
)
print(" ⚠️ 当前查询范围内没有数据,终止并关闭标签页。")
try:
page.locator(".mini-tab", has_text="到件扫描监控").locator(
".mini-tab-close"
@@ -404,7 +399,6 @@ def zto_actual_download(page):
_zto_poll_and_download_tasks(
page,
export_times,
target_task_title,
download_dir,
"中通-实到货物数据.xlsx",
)
@@ -414,9 +408,7 @@ def zto_actual_download(page):
return False
def _zto_poll_and_download_tasks(
page, export_times, target_task_title, download_dir, final_filename
):
def _zto_poll_and_download_tasks(page, export_times, download_dir, final_filename):
"""中通离线任务的轮询与下载"""
print("\n>> 正在前往【导出任务管理】界面...")
zto_smart_menu_click(page, ["系统配置", "导出任务管理"])
@@ -439,30 +431,29 @@ def _zto_poll_and_download_tasks(
ready_timestamps = set()
processing_timestamps = set()
# 单账号无并发:仅按提交时间容差(40s)认领本批任务,不再校验任务标题
# (站点可能调整标题名,写死标题会导致匹配失败、任务一直查不到)。
for i in range(row_count):
tds = task_rows.nth(i).locator("td")
if tds.count() < 10:
continue
title_str = tds.nth(3).inner_text().strip()
submit_time_str = tds.nth(4).inner_text().strip()
status_str = tds.nth(6).inner_text().strip()
if title_str == target_task_title:
try:
row_time = datetime.strptime(submit_time_str, "%Y-%m-%d %H:%M:%S")
matched = any(
abs((row_time - et).total_seconds()) <= 20
for et in export_times
)
try:
row_time = datetime.strptime(submit_time_str, "%Y-%m-%d %H:%M:%S")
matched = any(
abs((row_time - et).total_seconds()) <= 40 for et in export_times
)
if matched:
if status_str == "成功执行":
ready_timestamps.add(submit_time_str)
else:
processing_timestamps.add(submit_time_str)
except Exception:
pass
if matched:
if status_str == "成功执行":
ready_timestamps.add(submit_time_str)
else:
processing_timestamps.add(submit_time_str)
except Exception:
pass
total_found = len(ready_timestamps) + len(processing_timestamps)
print(