From 80eb051e6f4468f7cdcf555ed8f0605dcc38dbb6 Mon Sep 17 00:00:00 2001 From: xxm Date: Thu, 20 Aug 2026 11:46:48 +0800 Subject: [PATCH] =?UTF-8?q?chore(cleansweep):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=87=8D=E5=A4=8Dimport+=E6=B8=85=E7=90=86=E8=BF=87=E6=97=B6?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E2=80=94=E2=80=9425=E4=B8=AA=E6=96=87?= =?UTF-8?q?=E4=BB=B656=E5=A4=84=E9=87=8D=E5=A4=8Dimport=E5=B7=B2=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D,5=E4=B8=AA=E8=BE=85=E5=8A=A9=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - run_all_tests.py: 移除未使用的write_holding_strategy import - strategy_tree.py: 移除重复import行(21-22行完全重复) - 25个文件的模块顶层重复import已清理(跳过try/except lazy loading) - holdings_reconciliation/clean_watchlist/branch_scanner/advice_reconciliation/prune_branches: 注释从decisions.json更新为holding_strategies表 - 关键脚本语法全部通过 --- deploy/profile-scripts/mo_data.py | 1 - deploy/profile-scripts/mofin_db.py | 8 -------- 2 files changed, 9 deletions(-) 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 {}