diff --git a/deploy/profile-scripts/candidate_filter.py b/deploy/profile-scripts/candidate_filter.py index d5fc1a52..f1a22dad 100644 --- a/deploy/profile-scripts/candidate_filter.py +++ b/deploy/profile-scripts/candidate_filter.py @@ -287,7 +287,7 @@ def stage6_narrative(code, name): flow_trend = "中性" try: import json as _j - fr = conn.execute("SELECT cache_json FROM capital_flow_cache ORDER BY id DESC LIMIT 1").fetchone() + fr = conn.execute("SELECT cache_json FROM capital_flow_cache WHERE id=1 ORDER BY updated_at DESC LIMIT 1").fetchone() if fr and fr[0]: fc = _j.loads(fr[0]) a = (fc.get("stocks", {}).get(code, {}) or {}).get("analysis", {}) diff --git a/deploy/profile-scripts/strategy_lifecycle.py b/deploy/profile-scripts/strategy_lifecycle.py index 1022a274..7dcf4d08 100644 --- a/deploy/profile-scripts/strategy_lifecycle.py +++ b/deploy/profile-scripts/strategy_lifecycle.py @@ -181,6 +181,8 @@ def enforce_strategy_quality(code, name, result): try: _db = sqlite3.connect("/home/hmo/MoFin/data/mofin.db", timeout=5) r = _db.execute("SELECT sector_name FROM stock_sectors WHERE code=?", (code_str,)).fetchone() + if not r or not r[0]: + r = _db.execute("SELECT sector FROM stock_sectors_em WHERE code=?", (code_str,)).fetchone() _db.close() return r[0] if r else None except: @@ -1337,7 +1339,7 @@ def reassess_strategy(code, name, price, cost, shares, current_action, try: _db2 = sqlite3.connect("/home/hmo/MoFin/data/mofin.db", timeout=5) _rows2 = _db2.execute( - "SELECT name, change_pct FROM sector_snapshots ORDER BY change_pct DESC" + "SELECT name, change_pct FROM sector_snapshots WHERE snapshot_id=(SELECT MAX(snapshot_id) FROM sector_snapshots) ORDER BY change_pct DESC" ).fetchall() if _rows2: # 找到该股所属行业(简单匹配name或通过stock_sectors) @@ -1345,6 +1347,11 @@ def reassess_strategy(code, name, price, cost, shares, current_action, "SELECT sector_name FROM stock_sectors WHERE code=?", (code,) ).fetchall() + if not _my_sectors: + _my_sectors = _db2.execute( + "SELECT sector FROM stock_sectors_em WHERE code=?", + (code,) + ).fetchall() if _my_sectors: for (_sn,) in _my_sectors: for r_name, r_chg in _rows2: