Files

58 lines
2.2 KiB
Python

import os, shutil, glob
from datetime import datetime
ARCHIVE = f'/home/hmo/MoFin/archive/json-legacy-20260720'
os.makedirs(ARCHIVE, exist_ok=True)
# 保留的活文件(在用,不动)
KEEP = {
'evaluation.json', # evaluator 在读
'accuracy_stats.json', # strategy_feedback 在读
'format_error_library.json', # 在用 (9d)
'candidate_pool.json', # 在用 (3d)
'pipeline_registry.json', # 在用 (3d)
# 今天还在写的
'growth_registry.json', 'hardcode_audit.json', 'health_checklist.json',
'macro_divergence_state.json', 'macro_risk_state.json', 'market.json',
'mofin_health.json', 'portfolio.json', 'preflight_result.json',
'price_history.json', 'scanner_state.json', 'state.db',
'strategy_staleness_report.json', 'system_audit_report.json',
'mofin.db', 'mofin.db-shm', 'mofin.db-wal',
'analyst-knowledge-log.md', 'mofin_health.html', 'evaluation_input.json',
'push_cooldown.json', 'system_audit.json', 'system_inventory.json',
'watchlist.json.bak2',
}
DATA = '/home/hmo/web-dashboard/data' # = MoFin/data 硬链接
moved = 0
for f in sorted(os.listdir(DATA)):
p = os.path.join(DATA, f)
if not os.path.isfile(p):
continue
if f in KEEP:
continue
if f.startswith('.'):
continue
# 只归档 json/db/txt/log/md 类数据文件,别的不动
if not any(f.endswith(ext) for ext in ('.json', '.db', '.txt')):
continue
# 归档目标明确为遗留:>7天未修改
age_d = (datetime.now().timestamp() - os.path.getmtime(p)) / 86400
if age_d < 7:
continue
shutil.move(p, os.path.join(ARCHIVE, f))
moved += 1
print(f' archived: {f} ({age_d:.0f}d)')
print(f'\narchived {moved} files -> {ARCHIVE}')
# 废弃小库
print('\n=== 废弃小库 ===')
for f in ['market.db', 'market_data.db', 'stock_analysis.db']:
p = os.path.join(DATA, f)
if os.path.exists(p):
print(f' {f}: 已在归档中' if not os.path.exists(p) else '')
# 上面已经按 >7d 规则归档了(27d/21d 的 db 文件),确认:
for f in ['market.db', 'market_data.db', 'stock_analysis.db']:
archived = os.path.join(ARCHIVE, f)
print(f' {f}: {"ARCHIVED" if os.path.exists(archived) else "still present!"}')