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
import pandas as pd
from paths import DOWNLOAD_DIR, CONFIG_PATH
def _wait_and_get_frame(page, text_indicator, timeout_ms=20000):
"""动态雷达探测器:全域扫描所有视窗"""
@@ -14,14 +16,14 @@ def _wait_and_get_frame(page, text_indicator, timeout_ms=20000):
try:
if page.get_by_text(text_indicator).count() > 0:
return page
except:
except Exception:
pass
for frame in page.frames:
try:
if frame.get_by_text(text_indicator).count() > 0:
return frame
except:
except Exception:
pass
page.wait_for_timeout(300)
@@ -49,7 +51,7 @@ def zto_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)
@@ -67,8 +69,8 @@ def zto_expected_download(page):
# 读取 YAML 配置设定天数
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("zto", {}).get("query_days", 1))
except Exception as e:
@@ -146,7 +148,7 @@ def zto_expected_download(page):
page.locator(".mini-tab", has_text="进站交接单查询").locator(
".mini-tab-close"
).click()
except:
except Exception:
pass
return
else:
@@ -155,7 +157,7 @@ def zto_expected_download(page):
page.locator(".mini-tab", has_text="进站交接单查询").locator(
".mini-tab-close"
).click()
except:
except Exception:
pass
return
else:
@@ -257,7 +259,7 @@ def zto_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)
@@ -275,8 +277,8 @@ def zto_actual_download(page):
# 2. 读取 YAML 并设定时间范围
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("zto", {}).get("query_days", 1))
except Exception:
@@ -344,7 +346,7 @@ def zto_actual_download(page):
page.locator(".mini-tab", has_text="到件扫描监控").locator(
".mini-tab-close"
).click()
except:
except Exception:
pass
return