From 35e2486e41a12bd3a4aaed7a56c4d0e8de5b107f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=A5=E5=BE=AE?= Date: Thu, 9 Jul 2026 21:25:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9F=BA=E6=9C=AC=E9=9D=A2=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E4=BB=8E=E8=85=BE=E8=AE=AFAPI=E6=8B=89(=E9=9A=8F?= =?UTF-8?q?=E6=97=B6=E5=8F=AF=E7=94=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/per_stock_reassess.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/per_stock_reassess.py b/scripts/per_stock_reassess.py index f64206a5..a33204b9 100644 --- a/scripts/per_stock_reassess.py +++ b/scripts/per_stock_reassess.py @@ -83,12 +83,28 @@ def _build_full_analysis(code, entry, result): macro_desc = "腾讯实时 " + " ".join(_parts[:3]) except: pass - # 基本面 - _f = _db.execute("SELECT pe, pb, eps FROM stock_fundamentals WHERE code=?", (code,)).fetchone() - if _f: - if _f[0]: pe_val = f"PE={_f[0]:.1f}" - if _f[1]: pb_val = f"PB={_f[1]:.2f}" - if _f[2]: pe_val += f" EPS={_f[2]:.2f}" if pe_val else f"EPS={_f[2]:.2f}" + # 基本面:直接从腾讯API拉(静态数据,随时可用) + try: + _pfx = "sh" if str(code).startswith(("6", "9")) else "sz" + _r3 = __import__('subprocess').run(["curl", "-s", f"http://qt.gtimg.cn/q={_pfx}{code}"], + capture_output=True, timeout=10) + _txt3 = _r3.stdout.decode("gbk", errors="ignore") + _p3 = _txt3.split("~") + if len(_p3) > 45: + _pe = _p3[39] if _p3[39] else "" + _pb = _p3[40] if len(_p3) > 40 and _p3[40] else "" + _mcap = _p3[44] if len(_p3) > 44 and _p3[44] else "" + _name3 = _p3[1] if _p3[1] else "" + if _pe: pe_val = f"PE={_pe}" + if _pb: pb_val = f"PB={_pb}" + if _mcap: + mcap_val = f"市值{float(_mcap)/10000:.1f}亿" if float(_mcap) > 10000 else f"市值{_mcap}万" + pe_val += f" {mcap_val}" if pe_val else mcap_val + # 如果还没有大盘数据,顺便从同一响应拿指数 + if not macro_desc: + macro_desc = f"{_name3}实时行情" + except: + pass _db.close() except Exception as _e: pass