From 8e94c7b4292ad1a2547caeaa91361b3f0d3e836a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E5=B7=A5?= Date: Thu, 27 Aug 2026 15:12:42 +0000 Subject: [PATCH] =?UTF-8?q?fix(HEL-199):=20=E4=B8=BA=E8=A1=A5=E6=A1=A3?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E8=A1=A5=E4=B8=8A=E4=BB=93=E5=BA=93=E6=A0=B9?= =?UTF-8?q?=20sys.path=20=E5=BC=95=E5=AF=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使 python3 tools/backfill_recent_snapshots.py --help 在干净环境下可直接运行,并同步文档运行示例为容器内执行。 Co-authored-by: Cursor Co-authored-by: multica-agent --- docs/maintenance/行情历史补档.md | 6 +++--- tools/backfill_recent_snapshots.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/maintenance/行情历史补档.md b/docs/maintenance/行情历史补档.md index 5425c56..c92d4c4 100644 --- a/docs/maintenance/行情历史补档.md +++ b/docs/maintenance/行情历史补档.md @@ -16,15 +16,15 @@ ## 上线步骤(总工执行) -在应用根目录: +在目标环境容器内执行(应用根目录;宿主机也可直接跑,脚本已自带仓库根 `sys.path` 引导): ```bash # 1) 只读规划:区分已有、真正缺档;不会写入 -python tools/backfill_recent_snapshots.py --account <管理员账号> --lookback 60 --dry-run --json +docker compose exec xiaobai-review python tools/backfill_recent_snapshots.py --account <管理员账号> --lookback 60 --dry-run --json # 2) 正式补档:先走 SQLite backup API 写 data/backups/review-pre-recent-backfill-*.db # 再对缺失交易日调用现有 sync_dashboard -python tools/backfill_recent_snapshots.py --account <管理员账号> --lookback 60 --json +docker compose exec xiaobai-review python tools/backfill_recent_snapshots.py --account <管理员账号> --lookback 60 --json # 3) 验证 # GET /api/sentiment/history?trade_date=YYYY-MM-DD&limit=60 diff --git a/tools/backfill_recent_snapshots.py b/tools/backfill_recent_snapshots.py index df1e48e..a9627ca 100644 --- a/tools/backfill_recent_snapshots.py +++ b/tools/backfill_recent_snapshots.py @@ -12,7 +12,13 @@ from __future__ import annotations import argparse import json +import sys from datetime import date +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) from backend.application import SERVICE from backend.bootstrap.config import normalize_date