diff --git a/deploy/profile-scripts/batch_reassess.py b/deploy/profile-scripts/batch_reassess.py index 14420474..4bf46858 100644 --- a/deploy/profile-scripts/batch_reassess.py +++ b/deploy/profile-scripts/batch_reassess.py @@ -179,11 +179,13 @@ def build_prompt(data): except: pass - # 拉取近期消息面(按代码/行业名匹配,无个股消息则带大盘级消息) + # 拉取近期消息面(stock 关联走 searched_stocks,失败不拖累大盘兜底) _news_note = "暂无近期消息" + _news_items = [] try: import sqlite3 as _sq _db = _sq.connect("/home/hmo/MoFin/data/mofin.db") + # ① 个股直接相关(searched_stocks 含本代码 或 行业名匹配) _sector_name = "" try: _sr = _db.execute( @@ -191,23 +193,23 @@ def build_prompt(data): _sector_name = _sr[0] if _sr else "" except Exception: pass - _nr = [] - if _sector_name: - _nr = _db.execute( + _nr = _db.execute( + "SELECT summary, overall_sentiment, created_at FROM signal_news " + "WHERE (searched_stocks LIKE ? OR sector LIKE ?) AND overall_sentiment IN ('利好','利空') " + "ORDER BY id DESC LIMIT 3", + (f'%{data["code"]}%', f'%{_sector_name}%')).fetchall() + _news_items.extend(_nr) + # ② 大盘兜底(独立 try,不被①的失败拖累) + if not _news_items: + _nr2 = _db.execute( "SELECT summary, overall_sentiment, created_at FROM signal_news " - "WHERE (code=? OR sector LIKE ?) AND overall_sentiment IN ('利好','利空') " - "ORDER BY id DESC LIMIT 3", - (data['code'], f'%{_sector_name}%')).fetchall() - if not _nr: - _nr = _db.execute( - "SELECT summary, overall_sentiment, created_at FROM signal_news " - "WHERE overall_sentiment IN ('利好','利空') " - "ORDER BY id DESC LIMIT 2").fetchall() - if _nr: - _news_note = " | ".join([f"{r[2][:10]} {r[1]} {r[0][:40]}" for r in _nr]) + "WHERE overall_sentiment IN ('利好','利空') ORDER BY id DESC LIMIT 2").fetchall() + _news_items.extend(_nr2) _db.close() except: pass + if _news_items: + _news_note = " | ".join([f"{r[2][:10]} {r[1]} {r[0][:40]}" for r in _news_items]) # ── 构建【原策略全文】section ── _params_parts = []