#!/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("开始批量更新简历数据...") # 1. 首先添加露营地运营行业(如果不存在) if '"露营地运营":' not in content: print("\n1. 添加露营地运营行业...") # 在宠物店经营后面添加 insert_pattern = r'("宠物店经营":\s*\[[^\]]*\])' replacement = r'\1,\n "露营地运营": []' content = re.sub(insert_pattern, replacement, content) print(" ✓ 露营地运营行业已添加") # 2. 为露营地运营专员添加完整数据 print("\n2. 添加露营地运营专员数据...") luyingdi_data = next((u for u in updates if u['position'] == '露营地运营专员'), None) if luyingdi_data: # 构建完整的岗位数据 luyingdi_entry = f''' {{ position: "露营地运营专员", level: "普通岗", content: {{ original: "露营地运营专员简历内容", modified: "露营地运营专员简历内容" }}, studentInfo: {{ project_experience: {{ project_name: "{luyingdi_data['studentInfo']['project_experience']['project_name']}", position: "{luyingdi_data['studentInfo']['project_experience']['position']}", time_period: "{luyingdi_data['studentInfo']['project_experience']['time_period']}", company: "{luyingdi_data['studentInfo']['project_experience']['company']}", description: `{luyingdi_data['studentInfo']['project_experience']['description']}` }}, core_skills: {json.dumps(luyingdi_data['studentInfo']['core_skills'], ensure_ascii=False, indent=10)}, compound_skills: {json.dumps(luyingdi_data['studentInfo']['compound_skills'], ensure_ascii=False, indent=10)}, personal_summary: "{luyingdi_data['studentInfo']['personal_summary']}" }} }}''' # 在露营地运营数组中添加数据 pattern = r'("露营地运营":\s*\[)(\s*\])' replacement = rf'\1\n{luyingdi_entry}\n \2' content = re.sub(pattern, replacement, content) print(" ✓ 露营地运营专员数据已添加") # 3. 更新其他岗位的studentInfo positions_to_update = [ ('文创产品设计师', '文旅产品设计'), ('文创产品策划师', '文旅产品设计'), ('文创产品设计师助理', '文旅产品设计'), ('品牌策划运营专员', '品牌运营'), ('品牌公关', '品牌运营'), ('品牌推广专员', '品牌运营'), ('ip运营', '品牌运营'), ('IP运营总监助理', '品牌运营'), ('品牌公关管培生', '品牌运营') ] print("\n3. 更新其他岗位的studentInfo...") for position, industry in positions_to_update: update_data = next((u for u in updates if u['position'] == position), None) if not update_data: print(f" ⚠ 未找到{position}的更新数据") continue # 构建studentInfo student_info = f'''{{ project_experience: {{ project_name: "{update_data['studentInfo']['project_experience']['project_name']}", position: "{update_data['studentInfo']['project_experience']['position']}", time_period: "{update_data['studentInfo']['project_experience']['time_period']}", company: "{update_data['studentInfo']['project_experience']['company']}", description: `{update_data['studentInfo']['project_experience']['description']}` }}, core_skills: {json.dumps(update_data['studentInfo']['core_skills'], ensure_ascii=False, indent=10)}, compound_skills: {json.dumps(update_data['studentInfo']['compound_skills'], ensure_ascii=False, indent=10)}, personal_summary: "{update_data['studentInfo']['personal_summary']}" }}''' # 查找并替换studentInfo: null或缺失的studentInfo # 查找该岗位的位置 position_pattern = f'position: "{position}"' pos = content.find(position_pattern) if pos != -1: # 找到该岗位结束的位置(下一个岗位或数组结束) next_pos = content.find('position:', pos + len(position_pattern)) if next_pos == -1: # 可能是最后一个岗位,找数组结束 next_pos = content.find(']', pos) # 获取这段内容 section = content[pos:next_pos] # 检查是否有studentInfo: null if 'studentInfo: null' in section: # 替换studentInfo: null pattern = rf'(position: "{position}".*?studentInfo:\s*)null' replacement = rf'\1{student_info}' content = re.sub(pattern, replacement, content, flags=re.DOTALL) print(f" ✓ {position} studentInfo已更新") elif 'studentInfo:' not in section: # 没有studentInfo,需要添加 # 在content后面添加 pattern = rf'(position: "{position}".*?content:\s*{{[^}}]*}})(\s*}})' replacement = rf'\1,\n studentInfo: {student_info}\2' content = re.sub(pattern, replacement, content, flags=re.DOTALL) print(f" ✓ {position} studentInfo已添加") else: print(f" ℹ {position} 已有studentInfo") # 保存更新后的文件 with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f: f.write(content) print("\n✓ 所有更新已完成!")