fix(batch_reassess): 价格从stock_daily/live_prices读取,移除curl API直接调用

This commit is contained in:
xxm
2026-08-20 18:22:36 +08:00
parent 6396d6fe86
commit 6e7e9ca061
+19 -6
View File
@@ -261,12 +261,25 @@ def collect_data(code):
else:
prefix = "sz"
try:
r = subprocess.run(["curl", "-s", f"http://qt.gtimg.cn/q={prefix}{code}"], capture_output=True, timeout=10)
parts = r.stdout.decode("gbk", errors="ignore").split("~")
data["price"] = float(parts[3]) if len(parts) > 3 and parts[3] else 0
data["pe"] = parts[39] if len(parts) > 39 and parts[39] else ""
data["mcap"] = parts[44] if len(parts) > 44 and parts[44] else ""
data["change_pct"] = parts[32] if len(parts) > 32 and parts[32] else "0"
_pconn = sqlite3.connect(DB, timeout=30)
_lp = _pconn.execute("SELECT price, change_pct FROM live_prices WHERE code=?", (code,)).fetchone()
if _lp and _lp[0]:
data["price"] = float(_lp[0])
data["change_pct"] = _lp[1] if _lp[1] is not None else "0"
else:
_sd = _pconn.execute("SELECT close FROM stock_daily WHERE code=? ORDER BY date DESC LIMIT 1", (code,)).fetchone()
data["price"] = float(_sd[0]) if _sd and _sd[0] else 0
data["change_pct"] = "0"
try:
_pfx = "hk" if len(str(code)) == 5 else ("sh" if str(code).startswith(("6","9")) else "sz")
_r = subprocess.run(["curl", "-s", f"http://qt.gtimg.cn/q={_pfx}{code}"], capture_output=True, timeout=10)
_parts = _r.stdout.decode("gbk", errors="ignore").split("~")
data["pe"] = _parts[39] if len(_parts) > 39 and _parts[39] else ""
data["mcap"] = _parts[44] if len(_parts) > 44 and _parts[44] else ""
except:
data["pe"] = ""
data["mcap"] = ""
_pconn.close()
except:
data["price"] = 0