refactor: remove duplicate scripts + JSON constants + update docs
This commit is contained in:
@@ -438,9 +438,6 @@ try:
|
||||
except ImportError:
|
||||
HAS_PROMPT_TRACKING = False
|
||||
|
||||
PORTFOLIO_PATH = "/home/hmo/web-dashboard/data/portfolio.json"
|
||||
WATCHLIST_PATH = "/home/hmo/web-dashboard/data/watchlist.json"
|
||||
|
||||
def safe_json_load(path, default=None):
|
||||
"""安全加载 JSON,遇到坏数据自动修复"""
|
||||
if not os.path.exists(path):
|
||||
@@ -2046,8 +2043,12 @@ def regenerate_all(stdout=True):
|
||||
pf = {"holdings": holdings}
|
||||
wl = {"stocks": wl_stocks}
|
||||
except Exception:
|
||||
pf = safe_json_load(PORTFOLIO_PATH, {})
|
||||
wl = safe_json_load(WATCHLIST_PATH, {})
|
||||
try:
|
||||
pf = read_portfolio()
|
||||
wl = read_watchlist()
|
||||
except Exception:
|
||||
pf = {}
|
||||
wl = {}
|
||||
|
||||
all_stocks = {}
|
||||
for item in pf.get("holdings", []):
|
||||
@@ -2068,7 +2069,7 @@ def regenerate_all(stdout=True):
|
||||
# 加载现有 decisions.json 以便追踪变更
|
||||
decisions_path = "/home/hmo/web-dashboard/data/decisions.json"
|
||||
try:
|
||||
existing_decisions = {d["code"]: d for d in mo_data.read_decisions().get("decisions", []) if d.get("code")}
|
||||
existing_decisions = {d["code"]: d for d in read_decisions().get("decisions", []) if d.get("code")}
|
||||
except:
|
||||
existing_decisions = {}
|
||||
|
||||
@@ -2445,7 +2446,7 @@ def regenerate_all(stdout=True):
|
||||
|
||||
# 写回数据文件 — 保留现有字段(现金、总资产等)不丢
|
||||
try:
|
||||
existing_pf = mo_data.read_portfolio()
|
||||
existing_pf = read_portfolio()
|
||||
except Exception:
|
||||
existing_pf = {}
|
||||
# 保留 price/change_pct — price_monitor 维护的实时价,regenerate_all 不应清除
|
||||
|
||||
Reference in New Issue
Block a user