import os
import subprocess
import json

# 用户ID列表
user_ids = [
    10781,
    20712,
    20854,
    25286,
    26386,
    26851,
    27090,
    27628,
    28724,
    28924,
    28935,
    28991,
    29038,
    29368,
    29559
]

# 生成每个用户对应的Level
def get_level(user_id):
    user_id_str = str(user_id)
    if user_id_str.startswith('1'):
        return 1
    elif user_id_str.startswith('2'):
        return 2
    else:
        return 1 # 默认Level1

# 尝试生成Unit1到Unit12的报告
max_unit = 12
script_path = "/root/.openclaw/workspace-xiaoban/skills/study-analysis/scripts/analysis.py"

for user_id in user_ids:
    level = get_level(user_id)
    print(f"\n=== 开始处理用户 {user_id} Level {level} ===")
    for unit in range(1, max_unit + 1):
        print(f"处理Unit {unit}...")
        cmd = f"cd /root/.openclaw/workspace-xiaoban && python3 {script_path} {user_id} {level} {unit}"
        try:
            result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=30)
            if result.returncode == 0:
                print(f"✅ 用户{user_id} L{level} U{unit} 分析成功")
                print(result.stdout.strip())
            else:
                print(f"❌ 用户{user_id} L{level} U{unit} 分析失败，跳过")
                break # 如果当前Unit失败，说明没有更多单元了，跳出循环
        except Exception as e:
            print(f"❌ 用户{user_id} L{level} U{unit} 执行出错: {e}")
            break

print("\n=== 所有用户处理完成 ===")
