From 40a75554aab23077cd2a6db82450ef91abc95fc1 Mon Sep 17 00:00:00 2001 From: hmo Date: Wed, 22 Jul 2026 13:31:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B6=88=E6=81=AF=E9=9D=A2=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2code=E5=88=97=E4=B8=8D=E5=AD=98=E5=9C=A8(searched=5Fst?= =?UTF-8?q?ocks)=E5=AF=BC=E8=87=B4=E6=95=B4=E4=B8=AAtry=E5=9D=97=E6=AD=BB?= =?UTF-8?q?=E4=BA=A1=E2=80=94=E2=80=94=E6=94=B9=E5=88=97=E5=90=8D+?= =?UTF-8?q?=E5=85=9C=E5=BA=95=E7=8B=AC=E7=AB=8Btry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/batch_reassess.py | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) 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 = []