diff --git a/deploy/profile-scripts/mo_data.py b/deploy/profile-scripts/mo_data.py index cb168a13..fee5e990 100644 --- a/deploy/profile-scripts/mo_data.py +++ b/deploy/profile-scripts/mo_data.py @@ -257,7 +257,6 @@ def get_prices_batch(codes, max_age_minutes=5): # 2. 缺失的调 API if need_api: try: - import subprocess, json r = subprocess.run( [sys.executable, str(SCRIPT_DIR / "stock_quote.py")] + need_api, capture_output=True, text=True, timeout=30 diff --git a/deploy/profile-scripts/mofin_db.py b/deploy/profile-scripts/mofin_db.py index bf63fff8..f65e78ea 100644 --- a/deploy/profile-scripts/mofin_db.py +++ b/deploy/profile-scripts/mofin_db.py @@ -1092,7 +1092,6 @@ def get_price_from_db(code: str) -> tuple[float | None, float | None]: 所有脚本应优先调用此函数,DB 无数据时才拉腾讯 API。 """ try: - import sqlite3 db = sqlite3.connect('/home/hmo/web-dashboard/data/mofin.db') db.row_factory = sqlite3.Row row = db.execute( @@ -1116,7 +1115,6 @@ def get_prices_batch_from_db(codes: list[str]) -> dict: if not codes: return results try: - import sqlite3 db = sqlite3.connect('/home/hmo/web-dashboard/data/mofin.db') db.row_factory = sqlite3.Row for code in codes: @@ -1941,7 +1939,6 @@ def push_recommend_alert(conn, code: str): print(f" [ALERT] {code} 止盈{tp}不合理,不推", flush=True); return False import sys as _s, os as _o _s.path.insert(0, _o.path.dirname(_o.path.abspath(__file__))) - from alert_helper import notify, ACTION _mid_xmpp = f"{(el+eh)/2:.2f}" if el > 0 and eh > el else "—" msg = (f"📈 {name or code}({code}) 价{price}→12维{sig}!" f"区间{el}→{_mid_xmpp}←{eh} 损{sl} 盈{tp} RR={rr or 0} 仓位{pos or '-'}") @@ -2343,7 +2340,6 @@ def query_cash_log(conn, limit: int = 20) -> list[dict]: def write_live_prices(conn, prices: dict): """写入实时价格快照(替代 live_prices.json)""" - import json for code, info in prices.items(): conn.execute( "INSERT OR REPLACE INTO live_prices (code, price, change_pct, updated_at) VALUES (?,?,?,datetime('now','localtime'))", @@ -2357,14 +2353,12 @@ def read_live_prices(conn) -> dict: def write_mtf_cache(conn, code: str, data: dict): """写入多周期缓存(替代 multi_tf_cache.json 单条)""" - import json conn.execute( "INSERT OR REPLACE INTO mtf_cache (code, cache_json, updated_at) VALUES (?,?,datetime('now','localtime'))", (code, json.dumps(data, ensure_ascii=False)) ) def read_mtf_cache(conn, code: str) -> dict: - import json r = conn.execute("SELECT cache_json FROM mtf_cache WHERE code=?", (code,)).fetchone() return json.loads(r['cache_json']) if r else {} @@ -2376,7 +2370,6 @@ def write_capital_flow_cache(conn, data: dict): 持写锁过久,导致并发 cron (candidate_filter 等) database is locked。 改为固定 id=1 单行 upsert,锁持有时间从秒级降至毫秒级。 """ - import json conn.execute( "INSERT INTO capital_flow_cache (id, cache_json, updated_at) VALUES (1,?,datetime('now','localtime')) " "ON CONFLICT(id) DO UPDATE SET cache_json=excluded.cache_json, updated_at=excluded.updated_at", @@ -2384,7 +2377,6 @@ def write_capital_flow_cache(conn, data: dict): ) def read_capital_flow_cache(conn) -> dict: - import json r = conn.execute("SELECT cache_json FROM capital_flow_cache WHERE id=1 ORDER BY updated_at DESC LIMIT 1").fetchone() return json.loads(r['cache_json']) if r else {}