From 0afff445b62c47596d172f2c5741995f3acb8999 Mon Sep 17 00:00:00 2001 From: xxm Date: Sat, 22 Aug 2026 12:03:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20price=5Fmonitor=20record=5Fevent=20?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E5=AE=88=E5=8D=AB=EF=BC=88=E4=B8=8A=E6=AC=A1?= =?UTF-8?q?=E8=A2=ABdeploy=5Fguard=E5=9B=9E=E6=BB=9A=EF=BC=8C=E9=87=8D?= =?UTF-8?q?=E6=89=93=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/price_monitor.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/deploy/profile-scripts/price_monitor.py b/deploy/profile-scripts/price_monitor.py index 412b8c3a..36a0f241 100644 --- a/deploy/profile-scripts/price_monitor.py +++ b/deploy/profile-scripts/price_monitor.py @@ -515,8 +515,26 @@ def record_event(code, name, event_type, price, trigger_value, event_label=""): _exch, _typ = ("SH", "A") else: _exch, _typ = ("SZ", "A") + # 2026-08-22 名称治理:无名字先查 stocks 已有真名,再腾讯 quote 兜底,杜绝 name=code 垃圾行 + if not name: + try: + _r = _c.execute("SELECT name FROM stocks WHERE code=?", (str(code),)).fetchone() + if _r and _r[0] and _r[0] != str(code): + name = _r[0] + except Exception: + pass + if not name: + try: + from mofin_db import fetch_stock_name_tencent + name = fetch_stock_name_tencent(code) or "" + except Exception: + pass _c.execute("INSERT OR IGNORE INTO stocks (code, name, exchange, type, updated_at) VALUES (?,?,?,?,?)", (str(code), name or str(code), _exch, _typ, now)) + if name: + # 治愈已有 name=code 的坏行(INSERT OR IGNORE 不会更新已存在行) + _c.execute("UPDATE stocks SET name=?, updated_at=? WHERE code=? AND name=?", + (name, now, str(code), str(code))) _c.commit() write_price_event(_c, code=code, name=name, event_type=event_type, price=round(price, 2), trigger_value=str(trigger_value),