migrate: remove JSON, DB-only — mo_data, server, scripts, prompts (27 files)
This commit is contained in:
@@ -15,6 +15,8 @@ import_holding_xls.py — 从 holding.xls 导入持仓到全系统
|
||||
"""
|
||||
import csv, json, sys, subprocess, sqlite3, os
|
||||
from datetime import datetime
|
||||
from mo_data import read_decisions
|
||||
from mofin_db import get_conn, write_holdings_batch, write_portfolio_summary, write_holding_strategy
|
||||
|
||||
STOCKS_FILE = "/home/hmo/stocks/holding.xls"
|
||||
PORTFOLIO_PATH = "/home/hmo/web-dashboard/data/portfolio.json"
|
||||
@@ -149,11 +151,11 @@ def main():
|
||||
'updated_at': datetime.now().strftime('%Y-%m-%d %H:%M'),
|
||||
'source': STOCKS_FILE,
|
||||
}
|
||||
with open(PORTFOLIO_PATH, 'w') as f:
|
||||
json.dump(portfolio, f, indent=2, ensure_ascii=False)
|
||||
# [migrated to DB] — cold backup removed; DB writes below
|
||||
# with open(PORTFOLIO_PATH, 'w') as f:
|
||||
# json.dump(portfolio, f, indent=2, ensure_ascii=False)
|
||||
# DB 写入
|
||||
try:
|
||||
from mofin_db import get_conn, write_holdings_batch, write_portfolio_summary
|
||||
conn = get_conn()
|
||||
write_holdings_batch(conn, portfolio.get('holdings', []))
|
||||
write_portfolio_summary(conn, portfolio)
|
||||
@@ -165,8 +167,7 @@ def main():
|
||||
print("\n→ 重建决策树...")
|
||||
sys.path.insert(0, '/home/hmo/web-dashboard')
|
||||
from strategy_tree import init_default_branches
|
||||
with open('/home/hmo/web-dashboard/data/decisions.json') as f:
|
||||
data = json.load(f)
|
||||
data = read_decisions()
|
||||
ok = 0
|
||||
for e in data.get('decisions', []):
|
||||
branches = init_default_branches(
|
||||
@@ -175,8 +176,17 @@ def main():
|
||||
e.get('stop_loss', 0), e.get('take_profit', 0))
|
||||
e['strategy_tree'] = {'branches': branches, 'created_at': datetime.now().strftime('%Y-%m-%d')}
|
||||
ok += 1
|
||||
with open('/home/hmo/web-dashboard/data/decisions.json', 'w') as f:
|
||||
json.dump(data, f, indent=2, ensure_ascii=False)
|
||||
# DB 写入(替代 json.dump)
|
||||
try:
|
||||
conn = get_conn()
|
||||
for d in data.get('decisions', []):
|
||||
_whs(conn, d.get('code', ''), d.get('name', ''), d)
|
||||
conn.close()
|
||||
except Exception:
|
||||
pass
|
||||
# [migrated to DB] — cold backup removed
|
||||
# with open('/home/hmo/web-dashboard/data/decisions.json', 'w') as f:
|
||||
# json.dump(data, f, indent=2, ensure_ascii=False)
|
||||
|
||||
print(f"\n{'='*50}")
|
||||
print(f"导入完成:{len(holdings)}只持仓")
|
||||
|
||||
Reference in New Issue
Block a user