import os
import json
import time
from datetime import datetime
import pathlib

ROOT_DIR = pathlib.Path(__file__).parent.parent.absolute()

def trigger_ea_data_export(days=60):
    to_ea_dir = ROOT_DIR / "bridge" / "to_ea"
    to_ea_dir.mkdir(parents=True, exist_ok=True)
    
    cmd_file = to_ea_dir / f"cmd_export_{int(time.time())}.json"
    
    cmd_data = {
        "action": "EXPORT_HISTORY",
        "days": days,
        "timestamp": datetime.now().isoformat()
    }
    
    with open(cmd_file, "w", encoding="utf-8") as f:
        json.dump(cmd_data, f)
        
    print(f"指令已下发: {cmd_file}")

if __name__ == "__main__":
    trigger_ea_data_export()
