import re

with open('index_main.html','r',encoding='utf-8') as f:
    html = f.read()

# 找到 VERIFIED_DETAILS 集合
vd_m = re.search(r'VERIFIED_DETAILS\s*=\s*new Set\(\[(.*?)\]\)', html, re.S)
if not vd_m:
    print('未找到 VERIFIED_DETAILS')
    exit(1)

vd_block = vd_m.group(1)
print(f'当前 VD 集合大小: {len(re.findall(r'"details/[^"]+"', vd_block))}')

# 新添加的5个详情页
new_vd = [
    'details/usc-c7891f2.html',
    'details/emory-computer-science-ms.html',
    'details/emory-data-science-datascims-ms.html',
    'details/berkeley-information-management-and-systems-ms.html',
    'details/ucla-master-of-applied-statistics-and-data-science-ms.html',
]

# 检查哪些已经在里面
to_add = []
for v in new_vd:
    if f'"{v}"' not in vd_block:
        to_add.append(v)
        print(f'  待添加: {v}')
    else:
        print(f'  已存在: {v}')

if not to_add:
    print('无需添加')
    exit(0)

# 在 VD 集合末尾添加
insert_text = ',\n  "' + '",\n  "'.join(to_add) + '"'
new_vd_block = vd_block.rstrip() + insert_text
html = html.replace(vd_block, new_vd_block)

with open('index_main.html','w',encoding='utf-8') as f:
    f.write(html)

print(f'成功添加 {len(to_add)} 个详情页到 VERIFIED_DETAILS')
