89 lines
3.1 KiB
Python
89 lines
3.1 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
# 读取清理后的数据
|
|||
|
|
with open('resume_updates_cleaned.json', 'r', encoding='utf-8') as f:
|
|||
|
|
updates = json.load(f)
|
|||
|
|
|
|||
|
|
# 读取resumeInterviewMock.js
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
print("批量更新所有岗位的完整studentInfo数据...")
|
|||
|
|
|
|||
|
|
# 需要更新的所有岗位
|
|||
|
|
all_positions = [
|
|||
|
|
'文创产品设计师',
|
|||
|
|
'文创产品策划师',
|
|||
|
|
'文创产品设计师助理',
|
|||
|
|
'品牌策划运营专员',
|
|||
|
|
'品牌公关',
|
|||
|
|
'品牌推广专员',
|
|||
|
|
'ip运营',
|
|||
|
|
'IP运营总监助理',
|
|||
|
|
'品牌公关管培生'
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
success_count = 0
|
|||
|
|
|
|||
|
|
for position in all_positions:
|
|||
|
|
update_data = next((u for u in updates if u['position'] == position), None)
|
|||
|
|
if not update_data:
|
|||
|
|
print(f"⚠ 未找到{position}的更新数据")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 准备完整的studentInfo数据
|
|||
|
|
student_info = update_data['studentInfo']
|
|||
|
|
|
|||
|
|
# 构建完整的studentInfo字符串
|
|||
|
|
student_info_str = f'''studentInfo: {{
|
|||
|
|
project_experience: {{
|
|||
|
|
project_name: "{student_info['project_experience']['project_name']}",
|
|||
|
|
position: "{student_info['project_experience']['position']}",
|
|||
|
|
time_period: "{student_info['project_experience']['time_period']}",
|
|||
|
|
company: "{student_info['project_experience']['company']}",
|
|||
|
|
description: `{student_info['project_experience']['description']}`
|
|||
|
|
}},
|
|||
|
|
core_skills: {json.dumps(student_info['core_skills'], ensure_ascii=False, indent=10).replace('"', '`')},
|
|||
|
|
compound_skills: {json.dumps(student_info['compound_skills'], ensure_ascii=False, indent=10).replace('"', '`')},
|
|||
|
|
personal_summary: "{student_info['personal_summary']}"
|
|||
|
|
}}'''
|
|||
|
|
|
|||
|
|
# 使用正则表达式替换整个studentInfo部分
|
|||
|
|
# 查找模式:position: "岗位名"...studentInfo: {...}
|
|||
|
|
pattern = rf'(position:\s*"{re.escape(position)}"[^}}]*?)studentInfo:\s*{{[^}}]*(?:{{[^}}]*}}[^}}]*)*}}'
|
|||
|
|
|
|||
|
|
# 替换为新的studentInfo
|
|||
|
|
replacement = rf'\1{student_info_str}'
|
|||
|
|
|
|||
|
|
# 执行替换
|
|||
|
|
new_content, count = re.subn(pattern, replacement, content, flags=re.DOTALL)
|
|||
|
|
|
|||
|
|
if count > 0:
|
|||
|
|
content = new_content
|
|||
|
|
print(f"✓ {position} studentInfo已完整更新")
|
|||
|
|
success_count += 1
|
|||
|
|
else:
|
|||
|
|
print(f"⚠ {position} 未能匹配到studentInfo位置")
|
|||
|
|
|
|||
|
|
# 保存更新后的文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
print(f"\n✓ 成功更新 {success_count}/{len(all_positions)} 个岗位的数据!")
|
|||
|
|
|
|||
|
|
# 验证更新
|
|||
|
|
print("\n验证更新结果...")
|
|||
|
|
for position in all_positions[:3]: # 验证前3个
|
|||
|
|
if f'position: "{position}"' in content:
|
|||
|
|
pos = content.find(f'position: "{position}"')
|
|||
|
|
section = content[pos:pos+500]
|
|||
|
|
if 'project_experience: null' in section:
|
|||
|
|
print(f" ✗ {position} 仍有null值")
|
|||
|
|
elif 'project_experience: {' in section:
|
|||
|
|
print(f" ✓ {position} 已更新")
|
|||
|
|
else:
|
|||
|
|
print(f" ? {position} 状态未知")
|