fix: 资金流改Sina MoneyFlow(eastmoney 246不可达) + 消息面按行业名匹配+大盘兜底
This commit is contained in:
@@ -164,17 +164,30 @@ def build_prompt(data):
|
||||
except:
|
||||
pass
|
||||
|
||||
# 拉取近期消息面
|
||||
# 拉取近期消息面(按代码/行业名匹配,无个股消息则带大盘级消息)
|
||||
_news_note = "暂无近期消息"
|
||||
try:
|
||||
import sqlite3 as _sq
|
||||
_db = _sq.connect("/home/hmo/MoFin/data/mofin.db")
|
||||
_nr = _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'%{data.get("name","")[:4]}%')
|
||||
).fetchall()
|
||||
_sector_name = ""
|
||||
try:
|
||||
_sr = _db.execute(
|
||||
"SELECT sector FROM stock_sectors WHERE code=? LIMIT 1", (data['code'],)).fetchone()
|
||||
_sector_name = _sr[0] if _sr else ""
|
||||
except Exception:
|
||||
pass
|
||||
_nr = []
|
||||
if _sector_name:
|
||||
_nr = _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])
|
||||
_db.close()
|
||||
|
||||
Reference in New Issue
Block a user