Files
online_sys/frontend_智能制造/update_all_interview_questions.py
KQL a7242f0c69 Initial commit: 教务系统在线平台
- 包含4个产业方向的前端项目:智能开发、智能制造、大健康、财经商贸
- 已清理node_modules、.yoyo等大文件,项目大小从2.6GB优化至631MB
- 配置完善的.gitignore文件

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-12 18:16:55 +08:00

191 lines
7.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import re
from datetime import datetime
# 读取智能制造岗位简历数据
print("正在读取智能制造岗位简历.json...")
with open('网页未导入数据/智能制造产业/智能制造岗位简历.json', 'r', encoding='utf-8') as f:
smart_mfg_data = json.load(f)
# 读取当前mock文件
print("正在读取当前mock文件...")
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
mock_content = f.read()
# 备份原文件
backup_time = datetime.now().strftime('%Y%m%d_%H%M%S')
backup_file = f'src/mocks/resumeInterviewMock.js.backup_complete_{backup_time}'
with open(backup_file, 'w', encoding='utf-8') as f:
f.write(mock_content)
print(f"已创建备份文件: {backup_file}")
# 解析智能制造岗位简历数据,构建完整的面试题映射
interview_data_map = {}
for item in smart_mfg_data:
job_group = item.get('简历岗位群', '')
interview_content = item.get('面试题内容', '')
if job_group and interview_content:
# 解析面试题内容
questions_data = []
lines = interview_content.split('\n')
current_section = None
current_section_questions = []
section_id = 1
for line in lines:
line = line.strip()
if not line:
continue
# 大标题(如 # 一、xxx
if line.startswith('# '):
# 保存上一个section
if current_section and current_section_questions:
questions_data.append({
'id': f'group_q{section_id}',
'title': current_section,
'questions': current_section_questions
})
section_id += 1
current_section = line[2:].strip()
current_section_questions = []
# 问题编号(如 1. xxx 或 1、xxx
elif re.match(r'^(\d+)[\.、]\s+', line):
# 提取问题
question_match = re.match(r'^(\d+)[\.、]\s+(.+)', line)
if question_match:
question_text = question_match.group(2).strip()
# 查找后续的答案
answer_lines = []
line_index = lines.index(line) + 1
while line_index < len(lines):
next_line = lines[line_index].strip()
# 如果遇到下一个问题或章节,停止
if next_line.startswith('#') or re.match(r'^(\d+)[\.、]\s+', next_line):
break
# 如果是答案标记
if next_line.startswith('示例答案') or next_line.startswith('答案'):
# 提取答案内容
if '' in next_line or ':' in next_line:
answer_text = re.sub(r'^(示例答案|答案)[:]?\s*', '', next_line)
answer_lines.append(answer_text)
line_index += 1
# 继续读取多行答案
while line_index < len(lines):
next_line = lines[line_index].strip()
if not next_line or next_line.startswith('#') or re.match(r'^(\d+)[\.、]\s+', next_line):
break
answer_lines.append(next_line)
line_index += 1
break
elif next_line:
# 如果没有明确的答案标记,下一行非空内容可能就是答案
answer_lines.append(next_line)
line_index += 1
break
else:
line_index += 1
answer = ' '.join(answer_lines).strip()
current_section_questions.append({
'question': question_text,
'answer': answer
})
# 保存最后一个section
if current_section and current_section_questions:
questions_data.append({
'id': f'group_q{section_id}',
'title': current_section,
'questions': current_section_questions
})
interview_data_map[job_group] = questions_data
print(f"\n共解析 {len(interview_data_map)} 个岗位群的面试题数据")
# 更新mock文件中的面试题
def update_industry_questions(match):
full_match = match.group(0)
industry_name = match.group(1)
# 查找对应的面试题数据
if industry_name not in interview_data_map:
print(f" - {industry_name}: 保持原样(未找到对应数据)")
return full_match
questions_data = interview_data_map[industry_name]
# 构建新的questions数组
new_questions = []
for section_data in questions_data:
sub_questions = []
for idx, q in enumerate(section_data['questions']):
# 转义特殊字符
question_text = q['question'].replace('\\', '\\\\').replace('"', '\\"')
answer_text = q['answer'].replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n')
sub_questions.append(f'''{{
"id": "q{section_data['id'][7:]}_{idx+1}",
"question": "{question_text}",
"answer": "{answer_text}"
}}''')
section_title = section_data['title'].replace('\\', '\\\\').replace('"', '\\"')
new_questions.append(f'''{{
"id": "{section_data['id']}",
"question": "# {section_title}",
"subQuestions": [
{','.join(sub_questions)}
]
}}''')
# 替换questions部分
questions_str = ',\n '.join(new_questions)
# 构建完整的替换内容
result = match.group(0).split('"questions": [')[0]
result += '"questions": [\n '
result += questions_str
result += '\n ]'
# 统计题目数量
total_questions = sum(len(section['questions']) for section in questions_data)
print(f" - {industry_name}: 更新为 {len(questions_data)} 个章节,{total_questions} 道题")
return result
# 执行更新
print("\n正在更新面试题数据...")
pattern = r'"name":\s*"([^"]+)"[^}]*?"questions":\s*\[.*?\]\s*(?=\})'
new_content = re.sub(pattern, update_industry_questions, mock_content, flags=re.DOTALL)
# 保存更新后的文件
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
f.write(new_content)
print("\n✅ 面试题数据更新完成!")
# 验证语法
import subprocess
result = subprocess.run(['node', '-c', 'src/mocks/resumeInterviewMock.js'],
capture_output=True, text=True)
if result.returncode == 0:
print("✅ 语法检查通过!")
else:
print("❌ 语法错误:")
print(result.stderr)