177 lines
5.8 KiB
Python
177 lines
5.8 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""
|
|||
|
|
完整更新所有岗位群的面试题
|
|||
|
|
从智能制造岗位简历.json中提取完整数据
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
print("=== 完整更新所有岗位群面试题 ===\n")
|
|||
|
|
|
|||
|
|
# 1. 读取源数据
|
|||
|
|
print("1. 读取智能制造岗位简历.json...")
|
|||
|
|
with open('网页未导入数据/智能制造产业/智能制造岗位简历.json', 'r', encoding='utf-8') as f:
|
|||
|
|
source_data = json.load(f)
|
|||
|
|
|
|||
|
|
# 2. 解析所有面试题
|
|||
|
|
print("2. 解析面试题数据...")
|
|||
|
|
interview_questions_map = {}
|
|||
|
|
|
|||
|
|
for item in source_data:
|
|||
|
|
job_group = item.get('简历岗位群', '')
|
|||
|
|
interview_content = item.get('面试题内容', '')
|
|||
|
|
|
|||
|
|
if not job_group or not interview_content:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 收集所有问题(不分章节)
|
|||
|
|
all_questions = []
|
|||
|
|
|
|||
|
|
lines = interview_content.split('\n')
|
|||
|
|
i = 0
|
|||
|
|
while i < len(lines):
|
|||
|
|
line = lines[i].strip()
|
|||
|
|
|
|||
|
|
# 匹配问题编号
|
|||
|
|
question_match = re.match(r'^(\d+)[\.、]\s*(.+)', line)
|
|||
|
|
if question_match:
|
|||
|
|
question_text = question_match.group(2).strip()
|
|||
|
|
|
|||
|
|
# 查找答案
|
|||
|
|
answer = ""
|
|||
|
|
i += 1
|
|||
|
|
|
|||
|
|
# 继续查找答案
|
|||
|
|
while i < len(lines):
|
|||
|
|
next_line = lines[i].strip()
|
|||
|
|
|
|||
|
|
# 如果遇到下一个问题或章节,停止
|
|||
|
|
if re.match(r'^\d+[\.、]\s*', next_line) or next_line.startswith('#'):
|
|||
|
|
i -= 1
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 如果是答案标记
|
|||
|
|
if next_line and (next_line.startswith('答案') or next_line.startswith('示例答案')):
|
|||
|
|
answer = re.sub(r'^(答案|示例答案)[::]?\s*', '', next_line).strip()
|
|||
|
|
if not answer:
|
|||
|
|
i += 1
|
|||
|
|
if i < len(lines):
|
|||
|
|
answer = lines[i].strip()
|
|||
|
|
break
|
|||
|
|
elif next_line and not answer:
|
|||
|
|
# 如果没有答案标记,下一个非空行可能就是答案
|
|||
|
|
answer = next_line
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
i += 1
|
|||
|
|
|
|||
|
|
# 如果没有找到答案,提供默认答案
|
|||
|
|
if not answer:
|
|||
|
|
answer = "请根据实际情况回答"
|
|||
|
|
|
|||
|
|
all_questions.append({
|
|||
|
|
'question': question_text,
|
|||
|
|
'answer': answer
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
i += 1
|
|||
|
|
|
|||
|
|
if all_questions:
|
|||
|
|
interview_questions_map[job_group] = all_questions
|
|||
|
|
print(f" - {job_group}: 解析到 {len(all_questions)} 道题")
|
|||
|
|
|
|||
|
|
print(f"\n共解析 {len(interview_questions_map)} 个岗位群的面试题")
|
|||
|
|
|
|||
|
|
# 3. 读取当前mock文件
|
|||
|
|
print("\n3. 读取当前mock文件...")
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
mock_content = f.read()
|
|||
|
|
|
|||
|
|
# 4. 备份
|
|||
|
|
backup_time = datetime.now().strftime('%Y%m%d_%H%M%S')
|
|||
|
|
backup_file = f'src/mocks/resumeInterviewMock.js.backup_complete_{backup_time}'
|
|||
|
|
print(f"4. 创建备份: {backup_file}")
|
|||
|
|
with open(backup_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(mock_content)
|
|||
|
|
|
|||
|
|
# 5. 逐个岗位群更新
|
|||
|
|
print("\n5. 开始更新各岗位群...")
|
|||
|
|
updated_count = 0
|
|||
|
|
|
|||
|
|
for job_group, questions in interview_questions_map.items():
|
|||
|
|
print(f"\n处理 {job_group}...")
|
|||
|
|
|
|||
|
|
# 构建新的questions数组
|
|||
|
|
sub_questions = []
|
|||
|
|
for idx, q in enumerate(questions, 1):
|
|||
|
|
question_text = q['question'].replace('\\', '\\\\').replace('"', '\\"')
|
|||
|
|
answer_text = q['answer'].replace('\\', '\\\\').replace('"', '\\"').replace('\n', ' ')
|
|||
|
|
|
|||
|
|
sub_questions.append(f'''{{
|
|||
|
|
"id": "q1_{idx}",
|
|||
|
|
"question": "{question_text}",
|
|||
|
|
"answer": "{answer_text}"
|
|||
|
|
}}''')
|
|||
|
|
|
|||
|
|
# 构建完整的questions结构
|
|||
|
|
new_questions = f'''[
|
|||
|
|
{{
|
|||
|
|
"id": "group_q1",
|
|||
|
|
"question": "# {job_group}岗位面试题",
|
|||
|
|
"subQuestions": [
|
|||
|
|
{','.join(sub_questions)}
|
|||
|
|
]
|
|||
|
|
}}
|
|||
|
|
]'''
|
|||
|
|
|
|||
|
|
# 查找并替换该岗位群的questions部分
|
|||
|
|
pattern = rf'("name":\s*"{re.escape(job_group)}"[^}}]*?"questions":\s*)\[.*?\](\s*\}})'
|
|||
|
|
|
|||
|
|
# 执行替换
|
|||
|
|
old_content = mock_content
|
|||
|
|
mock_content = re.sub(pattern, r'\1' + new_questions + r'\2', mock_content, flags=re.DOTALL)
|
|||
|
|
|
|||
|
|
if old_content != mock_content:
|
|||
|
|
print(f" ✅ {job_group} 已更新为 {len(questions)} 道题")
|
|||
|
|
updated_count += 1
|
|||
|
|
else:
|
|||
|
|
print(f" ⚠️ {job_group} 未找到匹配位置")
|
|||
|
|
|
|||
|
|
# 6. 保存文件
|
|||
|
|
print(f"\n6. 保存更新后的文件...")
|
|||
|
|
print(f" 共更新 {updated_count} 个岗位群")
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(mock_content)
|
|||
|
|
|
|||
|
|
# 7. 验证语法
|
|||
|
|
print("\n7. 验证语法...")
|
|||
|
|
import subprocess
|
|||
|
|
result = subprocess.run(['node', '-c', 'src/mocks/resumeInterviewMock.js'],
|
|||
|
|
capture_output=True, text=True)
|
|||
|
|
if result.returncode == 0:
|
|||
|
|
print("✅ 语法检查通过!")
|
|||
|
|
print(f"\n=== 更新完成 ===")
|
|||
|
|
print(f"成功更新 {updated_count}/{len(interview_questions_map)} 个岗位群")
|
|||
|
|
|
|||
|
|
# 统计最终结果
|
|||
|
|
print("\n=== 最终统计 ===")
|
|||
|
|
for group in interview_questions_map.keys():
|
|||
|
|
pattern = rf'"name": "{re.escape(group)}".*?"questions": \[(.*?)\]\s*\}}'
|
|||
|
|
match = re.search(pattern, mock_content, re.DOTALL)
|
|||
|
|
if match:
|
|||
|
|
count = len(re.findall(r'"id": "q1_\d+', match.group(1)))
|
|||
|
|
expected = len(interview_questions_map[group])
|
|||
|
|
status = "✅" if count == expected else "⚠️"
|
|||
|
|
print(f" {status} {group}: {count}/{expected} 道题")
|
|||
|
|
else:
|
|||
|
|
print("❌ 语法错误:")
|
|||
|
|
print(result.stderr)
|
|||
|
|
print("\n正在恢复备份...")
|
|||
|
|
with open(backup_file, 'r', encoding='utf-8') as f:
|
|||
|
|
mock_content = f.read()
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(mock_content)
|
|||
|
|
print("已恢复到备份版本")
|