#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""检查「自动化新建会议」残留：登录会议列表，统计该名称的会议行数与状态。"""
import sys, time
sys.stdout.reconfigure(encoding="utf-8")
from app.executors.playwright_executor import PlaywrightExecutor

LIST_URL = "https://192.168.5.44/#/meetingV3?meetingV3=%2FmeetingV3%2F%23%2FmeetingAll"
NAME = "自动化新建会议"

executor = PlaywrightExecutor(config={"headless": True, "timeout": 60000, "screenshot": False, "auto_login": True})
executor.start()
executor.do_login()
page = executor._page
page.goto(LIST_URL, wait_until="domcontentloaded", timeout=30000)

# 等待表格加载
for i in range(30):
    time.sleep(1)
    cnt = page.locator('.el-table__row').count()
    if cnt > 0:
        break

# 统计该名称行 + 每行状态
data = page.evaluate(f"""() => {{
    const rows = [];
    document.querySelectorAll('.el-table__row').forEach(tr => {{
        const t = (tr.innerText||'');
        if (t.includes('{NAME}')) {{
            const statusCell = tr.querySelector('td:last-child');
            rows.push({{
                name: (tr.querySelector('td:nth-child(2)')||{{innerText:'?'}}).innerText.trim().slice(0,30),
                status: statusCell ? statusCell.innerText.trim().slice(0,20) : '?',
            }});
        }}
    }});
    return rows;
}}""")
print(f"残留会议「{NAME}」数量: {len(data)}")
for r in data:
    print("  -", r)
executor.stop()
