chore(cleansweep): 修复重复import+清理过时注释——25个文件56处重复import已修复,5个辅助模块注释更新
- 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表 - 关键脚本语法全部通过
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user