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

@@ -6,6 +6,8 @@ import yaml
from datetime import datetime, timedelta
import pandas as pd
from paths import DOWNLOAD_DIR, CONFIG_PATH
def yunda_login(page):
"""
@@ -26,8 +28,8 @@ def yunda_login(page):
# 从配置读取凭证(默认空串;真实凭据仅存于被忽略的 config.yaml
username = ""
password = ""
if os.path.exists("config.yaml"):
with open("config.yaml", "r", encoding="utf-8") as f:
if os.path.exists(CONFIG_PATH):
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
config = yaml.safe_load(f) or {}
yd_cfg = config.get("yunda", {})
username = str(yd_cfg.get("username", ""))
@@ -91,7 +93,7 @@ def yunda_expected_download(page):
print("\n▶ 开始执行【韵达 - 应到货物数据下载】任务...")
target_task_title = "进站主单表"
download_dir = os.path.join(os.getcwd(), "downloads")
download_dir = DOWNLOAD_DIR
if not os.path.exists(download_dir):
os.makedirs(download_dir)
@@ -116,8 +118,8 @@ def yunda_expected_download(page):
# 2. 从配置文件中解析并计算绝对日期跨度
query_days = 1
try:
if os.path.exists("config.yaml"):
with open("config.yaml", "r", encoding="utf-8") as f:
if os.path.exists(CONFIG_PATH):
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
config = yaml.safe_load(f) or {}
query_days = int(config.get("yunda", {}).get("query_days", 1))
except Exception as e:
@@ -307,7 +309,7 @@ def yunda_actual_download(page):
print("\n▶ 开始执行【韵达 - 实到货物数据下载】任务...")
target_task_title = "扫描记录数据"
download_dir = os.path.join(os.getcwd(), "downloads")
download_dir = DOWNLOAD_DIR
if not os.path.exists(download_dir):
os.makedirs(download_dir)
@@ -331,8 +333,8 @@ def yunda_actual_download(page):
query_days = 1
try:
if os.path.exists("config.yaml"):
with open("config.yaml", "r", encoding="utf-8") as f:
if os.path.exists(CONFIG_PATH):
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
config = yaml.safe_load(f) or {}
query_days = int(config.get("yunda", {}).get("query_days", 1))
except Exception:
@@ -578,7 +580,7 @@ def _yunda_poll_and_download_tasks(
".el-icon-close"
).click()
print(" ✅ 【导出服务】工作区已安全关闭。")
except:
except Exception:
pass
if downloaded_files:
@@ -589,7 +591,7 @@ def _yunda_poll_and_download_tasks(
df = pd.read_excel(file_path, dtype=str)
if not df.empty:
all_dfs.append(df)
except:
except Exception:
pass
if all_dfs: