#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 更新resumeInterviewMock.js中的面试题数据 """ import json import re from datetime import datetime def update_interview_questions(): # 读取提取的面试题数据 with open('interview_questions_data.json', 'r', encoding='utf-8') as f: interview_data = json.load(f) # 读取当前的mock文件 with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f: mock_content = f.read() # 备份原文件 backup_name = f'src/mocks/resumeInterviewMock.js.backup_{datetime.now().strftime("%Y%m%d_%H%M%S")}_interview_questions' with open(backup_name, 'w', encoding='utf-8') as f: f.write(mock_content) print(f"已创建备份文件: {backup_name}") # 创建岗位群名称到面试题的映射 job_group_mapping = { "BIM建筑信息模型": interview_data.get("BIM建筑信息模型", []), "房地产经纪": interview_data.get("房地产经纪", []), "工程采购": interview_data.get("工程采购", []), "工程监理": interview_data.get("工程监理", []), "工程造价与资料管理": interview_data.get("工程造价与资料管理", []), "建筑安装工程": interview_data.get("建筑安装工程", []), "建筑测量": interview_data.get("建筑测量", []), "建筑工程检测": interview_data.get("建筑工程检测", []), "建筑工程设计": interview_data.get("建筑工程设计", []), "建筑工程制图": interview_data.get("建筑工程制图", []), "建筑节能": interview_data.get("建筑节能", []), "建筑施工与施工管理": interview_data.get("建筑施工与施工管理", []), "施工安全管理": interview_data.get("施工安全管理", []), "室内设计": interview_data.get("室内设计", []), "招投标管理": interview_data.get("招投标管理", []) } # 查找industries数组的位置 industries_match = re.search(r'const\s+industries\s*=\s*\[', mock_content) if not industries_match: print("未找到industries数组") return # 逐个查找并更新每个岗位群的questions字段 updated = 0 for job_group, questions in job_group_mapping.items(): if not questions: continue # 查找该岗位群的位置 pattern = rf'"name":\s*"{re.escape(job_group)}"[^}}]*?"questions":\s*\[[^\]]*?\]' matches = list(re.finditer(pattern, mock_content, re.DOTALL)) if matches: for match in matches: # 构建新的questions数组 questions_json = json.dumps([{ "id": f"group_{job_group}_q1", "question": f"{job_group}面试题", "subQuestions": questions[:10] # 限制每个岗位群最多10道题避免太长 }], ensure_ascii=False, indent=4) # 缩进调整 questions_json = questions_json.replace('\n', '\n ') # 替换questions字段 new_questions = f'"questions": {questions_json}' old_questions_match = re.search(r'"questions":\s*\[[^\]]*?\]', match.group(0), re.DOTALL) if old_questions_match: new_section = match.group(0).replace(old_questions_match.group(0), new_questions) mock_content = mock_content[:match.start()] + new_section + mock_content[match.end():] updated += 1 print(f"已更新 {job_group} 的面试题 ({len(questions)} 道题)") # 写入更新后的文件 with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f: f.write(mock_content) print(f"\n总共更新了 {updated} 个岗位群的面试题数据") print("更新完成!") if __name__ == "__main__": update_interview_questions()