import pandas as pd
import re
import os

# 读取完整剧本
with open('/root/.openclaw/workspace-xiaobian/output/Lesson_机器人进校园_完整剧本.md', 'r', encoding='utf-8') as f:
    content = f.read()

# 提取剧本表格内容
table_pattern = re.compile(r'\| 类型\s*\| 剧情描述\s*\| 名字\s*\| 台词\s*\|([\s\S]*?)\|---', re.MULTILINE)
rows = []
for line in content.split('\n'):
    if line.startswith('|') and not line.startswith('| ###') and not line.startswith('| 类型') and not line.startswith('|------'):
        parts = [p.strip() for p in line.split('|')[1:-1]]
        if len(parts) == 4:
            rows.append(parts)

# 创建DataFrame
df = pd.DataFrame(rows, columns=['类型', '剧情描述', '名字', '台词'])

# 导出Excel
output_path = '/root/.openclaw/workspace-xiaobian/output/Lesson_机器人进校园_完整剧本.xlsx'
df.to_excel(output_path, index=False, sheet_name='剧本')

print(f'Excel导出成功，保存路径：{output_path}')
print(f'文件大小：{os.path.getsize(output_path)/1024:.2f}KB')
