111 lines
3.5 KiB
Python
111 lines
3.5 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""
|
|||
|
|
最终更新所有岗位群的面试题数据
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
def final_update():
|
|||
|
|
# 读取面试题数据
|
|||
|
|
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:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 备份
|
|||
|
|
backup_name = f'src/mocks/resumeInterviewMock.js.backup_{datetime.now().strftime("%Y%m%d_%H%M%S")}_final'
|
|||
|
|
with open(backup_name, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print(f"已创建备份: {backup_name}")
|
|||
|
|
|
|||
|
|
# 定义所有岗位群
|
|||
|
|
all_job_groups = [
|
|||
|
|
"BIM建筑信息模型",
|
|||
|
|
"房地产经纪",
|
|||
|
|
"工程采购",
|
|||
|
|
"工程监理",
|
|||
|
|
"工程造价与资料管理",
|
|||
|
|
"建筑安装工程",
|
|||
|
|
"建筑测量",
|
|||
|
|
"建筑工程检测",
|
|||
|
|
"建筑工程设计",
|
|||
|
|
"建筑工程制图",
|
|||
|
|
"建筑节能",
|
|||
|
|
"建筑施工与施工管理",
|
|||
|
|
"施工安全管理",
|
|||
|
|
"室内设计",
|
|||
|
|
"招投标管理"
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
updated = 0
|
|||
|
|
|
|||
|
|
for job_group in all_job_groups:
|
|||
|
|
if job_group not in interview_data:
|
|||
|
|
print(f"警告: 未找到 {job_group} 的面试题数据")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
questions = interview_data[job_group]
|
|||
|
|
if not questions:
|
|||
|
|
print(f"警告: {job_group} 没有面试题")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 限制题目数量
|
|||
|
|
max_questions = min(8, len(questions)) # 限制为8道题
|
|||
|
|
selected_questions = questions[:max_questions]
|
|||
|
|
|
|||
|
|
# 构建questions数组
|
|||
|
|
questions_obj = [{
|
|||
|
|
"id": f"group_{job_group}_q1",
|
|||
|
|
"question": f"{job_group}面试题",
|
|||
|
|
"subQuestions": selected_questions
|
|||
|
|
}]
|
|||
|
|
|
|||
|
|
# 格式化JSON
|
|||
|
|
questions_json = json.dumps(questions_obj, ensure_ascii=False, indent=4)
|
|||
|
|
|
|||
|
|
# 查找岗位群位置并替换questions字段
|
|||
|
|
# 使用更精确的正则表达式
|
|||
|
|
pattern = rf'("name":\s*"{re.escape(job_group)}"[^{{}}]*?)(,\s*"questions":\s*)(\[[^\[\]]*?\])'
|
|||
|
|
|
|||
|
|
def replace_func(match):
|
|||
|
|
nonlocal updated
|
|||
|
|
# 调整缩进(假设缩进为4个空格)
|
|||
|
|
indented_json = questions_json.replace('\n', '\n ')
|
|||
|
|
updated += 1
|
|||
|
|
return match.group(1) + match.group(2) + indented_json
|
|||
|
|
|
|||
|
|
new_content, count = re.subn(pattern, replace_func, content, flags=re.DOTALL)
|
|||
|
|
|
|||
|
|
if count > 0:
|
|||
|
|
content = new_content
|
|||
|
|
print(f"✓ 已更新: {job_group} ({len(selected_questions)} 道题)")
|
|||
|
|
else:
|
|||
|
|
# 尝试替换空数组
|
|||
|
|
pattern2 = rf'("name":\s*"{re.escape(job_group)}"[^}}]*?"questions":\s*)\[\]'
|
|||
|
|
|
|||
|
|
def replace_func2(match):
|
|||
|
|
nonlocal updated
|
|||
|
|
indented_json = questions_json.replace('\n', '\n ')
|
|||
|
|
updated += 1
|
|||
|
|
return match.group(1) + indented_json
|
|||
|
|
|
|||
|
|
new_content2, count2 = re.subn(pattern2, replace_func2, content, flags=re.DOTALL)
|
|||
|
|
|
|||
|
|
if count2 > 0:
|
|||
|
|
content = new_content2
|
|||
|
|
print(f"✓ 已更新: {job_group} ({len(selected_questions)} 道题) [空数组]")
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
print(f"\n总共更新了 {updated} 个岗位群的面试题")
|
|||
|
|
return updated
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
final_update()
|