Centralize paths in paths.py and harden waybill-number handling

- Add paths.py: BASE_DIR/DOWNLOAD_DIR/CONFIG_PATH anchored on __file__
  so paths resolve regardless of the launch cwd
- Route main_router and all site modules through DOWNLOAD_DIR/CONFIG_PATH,
  replacing os.getcwd()-based download dirs and the "config.yaml" literal
- main_router compare engine: read Excel as str with keep_default_na,
  strip/normalize 运单号, drop blanks, and isin against a set so
  int/float-vs-str mismatches no longer produce false "undelivered"
- Shunxin: give downloaded files unique microsecond temp names and read
  Excel as str to preserve long-waybill precision
- Normalize bare except: to except Exception: across affected files

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-06-20 22:28:30 +08:00
parent 5d13c13f40
commit ab3f25a10e
6 changed files with 79 additions and 39 deletions

View File

@@ -5,6 +5,8 @@ import re
from datetime import datetime
import pandas as pd
from paths import DOWNLOAD_DIR
def _close_tab(page, tab_name):
"""关闭指定名称的标签页Ant Design Tabs
@@ -34,7 +36,7 @@ def shunxin_expected_download(page):
print("\n▶ 开始执行【顺心 - 应到货物数据下载】任务...")
# 初始化并创建下载目录
download_dir = os.path.join(os.getcwd(), "downloads")
download_dir = DOWNLOAD_DIR
if not os.path.exists(download_dir):
os.makedirs(download_dir)
print(f">> 已创建专属下载文件夹: {download_dir}")
@@ -189,10 +191,13 @@ def shunxin_expected_download(page):
).click()
download = download_info.value
save_path = os.path.join(download_dir, download.suggested_filename)
# 用带微秒的时间戳生成唯一临时文件名,避免同名任务相互覆盖导致丢数据
safe_timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
custom_filename = f"顺心_temp_{safe_timestamp}.xlsx"
save_path = os.path.join(download_dir, custom_filename)
download.save_as(save_path)
downloaded_files.append(save_path)
print(f" ⬇️ 文件已落盘: downloads/{download.suggested_filename}")
print(f" ⬇️ 文件已落盘: downloads/{custom_filename}")
except Exception as e:
print(f" ❌ 下载任务 [{time_str}] 失败: {e}")
@@ -202,7 +207,7 @@ def shunxin_expected_download(page):
all_data_frames = []
for file_path in downloaded_files:
try:
df = pd.read_excel(file_path)
df = pd.read_excel(file_path, dtype=str)
if not df.empty:
all_data_frames.append(df)
except Exception as e:
@@ -233,7 +238,7 @@ def shunxin_actual_download(page):
"""顺心:实到货物数据下载"""
print("\n▶ 开始执行【顺心 - 实到货物数据下载】任务...")
download_dir = os.path.join(os.getcwd(), "downloads")
download_dir = DOWNLOAD_DIR
if not os.path.exists(download_dir):
os.makedirs(download_dir)
@@ -358,10 +363,13 @@ def shunxin_actual_download(page):
).click()
download = download_info.value
save_path = os.path.join(download_dir, download.suggested_filename)
# 用带微秒的时间戳生成唯一临时文件名,避免同名任务相互覆盖导致丢数据
safe_timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
custom_filename = f"顺心_temp_{safe_timestamp}.xlsx"
save_path = os.path.join(download_dir, custom_filename)
download.save_as(save_path)
downloaded_files.append(save_path)
print(f" ⬇️ 文件已落盘: downloads/{download.suggested_filename}")
print(f" ⬇️ 文件已落盘: downloads/{custom_filename}")
except Exception as e:
print(f" ❌ 下载任务 [{time_str}] 失败: {e}")
@@ -371,7 +379,7 @@ def shunxin_actual_download(page):
all_data_frames = []
for file_path in downloaded_files:
try:
df = pd.read_excel(file_path)
df = pd.read_excel(file_path, dtype=str)
if not df.empty:
all_data_frames.append(df)
except Exception as e: