统一各站成败反馈信号;修复中通报错卡死与提示框误判
成败信号统一化(顺心/中通/韵达/安能/百世): - 各站 impl 开头清理上次的最终文件,避免无数据/失败时残留旧数据误导比对 - 轮询下载段加汇总校验:下载数 < 预期则 raise,堵住"零/部分下载被判成功" - 正常完成统一显式 return True(原中通/韵达/安能靠 None 隐式成功) - 无数据统一不落文件(安能实到不再落空 xlsx);韵达裸 except 改 except Exception - 中通"票数0无空提示"分支改判失败 中通 bug 修复(site_zto.py): - poll 加 stall 快速失败(连续4轮无进展即 raise)+ 刷新短超时 + 双失败 raise, 避免页面被遮挡时干等 5 分钟才触发重试 - "生成离线导出任务成功"提示所在 iframe 提交后被销毁,wait_for 抛 "Frame was detached" 属正常(提示已随 iframe 消失=任务已建立),改判成功 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -76,6 +76,15 @@ def _sanitize_for_filename(name):
|
||||
return re.sub(r'[\\/:*?"<>|]', "", str(name)).strip()
|
||||
|
||||
|
||||
def _remove_if_exists(path):
|
||||
"""删除文件(若存在):清理上次的本账号中间文件/最终文件,避免残留旧数据。"""
|
||||
try:
|
||||
if os.path.exists(path):
|
||||
os.remove(path)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def shunxin_belonging(page):
|
||||
"""读取顺心当前账号的归属网点名(仅在首页可见,须在导航离开首页前调用)。
|
||||
|
||||
@@ -118,7 +127,8 @@ def shunxin_merge_final(kind, tags):
|
||||
print(f" ⚠️ 读取中间文件 {mid_name} 失败: {e}")
|
||||
|
||||
if not frames:
|
||||
print(f">> ⚠️ 所有归属地均无{kind}数据,未生成 {final_name}。")
|
||||
print(f">> ⚠️ 所有归属地均无{kind}数据,删除残留的 {final_name}(不写空表)。")
|
||||
_remove_if_exists(final_path)
|
||||
return
|
||||
|
||||
combined = pd.concat(frames, ignore_index=True)
|
||||
@@ -182,6 +192,12 @@ def shunxin_expected_download_impl(page, out_tag=""):
|
||||
os.makedirs(download_dir)
|
||||
print(f">> 已创建下载目录: {download_dir}")
|
||||
|
||||
# 清理上次本账号的中间文件,避免本次无数据/失败时残留旧数据被 merge_final 误读
|
||||
_mid_suffix = f"-{out_tag}" if out_tag else ""
|
||||
_remove_if_exists(
|
||||
os.path.join(download_dir, f"顺心{_mid_suffix}-应到货物数据.xlsx")
|
||||
)
|
||||
|
||||
export_times = []
|
||||
target_task_timestamps = []
|
||||
|
||||
@@ -420,6 +436,12 @@ def shunxin_expected_download_impl(page, out_tag=""):
|
||||
except Exception as e:
|
||||
print(f" ❌ 下载任务 [{time_str}] 失败: {e}")
|
||||
|
||||
# 汇总校验:下载成功数必须等于目标任务数,否则判失败
|
||||
if len(downloaded_files) < len(target_task_timestamps):
|
||||
raise RuntimeError(
|
||||
f"仅成功下载 {len(downloaded_files)}/{len(target_task_timestamps)} 个任务,数据不完整"
|
||||
)
|
||||
|
||||
# 9. 合并数据
|
||||
if downloaded_files:
|
||||
print("\n>> 正在合并下载的数据...")
|
||||
@@ -499,6 +521,12 @@ def shunxin_actual_download_impl(page, out_tag=""):
|
||||
if not os.path.exists(download_dir):
|
||||
os.makedirs(download_dir)
|
||||
|
||||
# 清理上次本账号的中间文件,避免本次无数据/失败时残留旧数据被 merge_final 误读
|
||||
_mid_suffix = f"-{out_tag}" if out_tag else ""
|
||||
_remove_if_exists(
|
||||
os.path.join(download_dir, f"顺心{_mid_suffix}-实到货物数据.xlsx")
|
||||
)
|
||||
|
||||
export_times = []
|
||||
target_task_timestamps = []
|
||||
|
||||
@@ -710,6 +738,12 @@ def shunxin_actual_download_impl(page, out_tag=""):
|
||||
except Exception as e:
|
||||
print(f" ❌ 下载任务 [{time_str}] 失败: {e}")
|
||||
|
||||
# 汇总校验:下载成功数必须等于目标任务数,否则判失败
|
||||
if len(downloaded_files) < len(target_task_timestamps):
|
||||
raise RuntimeError(
|
||||
f"仅成功下载 {len(downloaded_files)}/{len(target_task_timestamps)} 个任务,数据不完整"
|
||||
)
|
||||
|
||||
# 8. 合并数据
|
||||
if downloaded_files:
|
||||
print("\n>> 正在合并下载的数据...")
|
||||
|
||||
Reference in New Issue
Block a user