107 lines
4.0 KiB
Python
107 lines
4.0 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
def extract_questions_from_content(content):
|
|||
|
|
"""从面试题内容中提取问题和答案"""
|
|||
|
|
questions = []
|
|||
|
|
|
|||
|
|
# 按问题编号分割内容
|
|||
|
|
pattern = r'\d+\.\s*问题[::]?\s*(.*?)(?=\d+\.\s*问题|$)'
|
|||
|
|
matches = re.findall(pattern, content, re.DOTALL)
|
|||
|
|
|
|||
|
|
for i, match in enumerate(matches, 1):
|
|||
|
|
# 提取问题和答案
|
|||
|
|
q_a_pattern = r'^(.*?)\n\s*(?:参考回答[::]?|回答[::]?)\s*(.*?)$'
|
|||
|
|
q_a_match = re.search(q_a_pattern, match.strip(), re.DOTALL)
|
|||
|
|
|
|||
|
|
if q_a_match:
|
|||
|
|
question_text = q_a_match.group(1).strip()
|
|||
|
|
answer_text = q_a_match.group(2).strip()
|
|||
|
|
|
|||
|
|
# 保留原始格式,包括换行和列表符号
|
|||
|
|
questions.append({
|
|||
|
|
"id": f"q{i}",
|
|||
|
|
"question": question_text,
|
|||
|
|
"answer": answer_text
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
return questions
|
|||
|
|
|
|||
|
|
def process_visual_design_data():
|
|||
|
|
"""处理视觉设计岗位简历数据"""
|
|||
|
|
|
|||
|
|
# 读取视觉设计岗位简历.json
|
|||
|
|
with open('网页未导入数据/视觉设计产业/视觉设计岗位简历.json', 'r', encoding='utf-8') as f:
|
|||
|
|
data = json.load(f)
|
|||
|
|
|
|||
|
|
# 为每个岗位提取面试题
|
|||
|
|
position_questions = {}
|
|||
|
|
|
|||
|
|
for item in data:
|
|||
|
|
position_name = item.get('岗位名称', '')
|
|||
|
|
interview_content = item.get('面试题内容', '')
|
|||
|
|
|
|||
|
|
if position_name and interview_content:
|
|||
|
|
# 提取该岗位的面试题
|
|||
|
|
questions = extract_questions_from_content(interview_content)
|
|||
|
|
|
|||
|
|
# 按类别分组(专业能力类、行为经历类、情景应变类)
|
|||
|
|
grouped_questions = {
|
|||
|
|
'专业能力类': [],
|
|||
|
|
'行为经历类': [],
|
|||
|
|
'情景应变类': []
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 根据内容判断类别
|
|||
|
|
current_category = '专业能力类'
|
|||
|
|
for q in questions:
|
|||
|
|
question_text = q['question'].lower()
|
|||
|
|
if '经历' in question_text or '分享' in question_text or '描述' in question_text or '项目' in question_text:
|
|||
|
|
current_category = '行为经历类'
|
|||
|
|
elif '如果' in question_text or '假设' in question_text or '应对' in question_text or '处理' in question_text:
|
|||
|
|
current_category = '情景应变类'
|
|||
|
|
|
|||
|
|
grouped_questions[current_category].append(q)
|
|||
|
|
|
|||
|
|
position_questions[position_name] = {
|
|||
|
|
'all': questions,
|
|||
|
|
'grouped': grouped_questions
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return position_questions
|
|||
|
|
|
|||
|
|
def update_resume_interview_mock(position_questions):
|
|||
|
|
"""更新resumeInterviewMock.js文件"""
|
|||
|
|
|
|||
|
|
# 读取现有的mock文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 为每个岗位更新questions字段
|
|||
|
|
for position_name, questions_data in position_questions.items():
|
|||
|
|
# 查找该岗位在mock文件中的位置
|
|||
|
|
pattern = rf'name:\s*["\']({re.escape(position_name)})["\'].*?questions:\s*\[(.*?)\]'
|
|||
|
|
|
|||
|
|
# 构建新的questions数组
|
|||
|
|
new_questions = json.dumps(questions_data['all'], ensure_ascii=False, indent=6)
|
|||
|
|
|
|||
|
|
# 替换questions内容
|
|||
|
|
# 这里需要更精确的处理,因为JS文件格式与JSON略有不同
|
|||
|
|
|
|||
|
|
# 为了保证数据完整性,生成一个单独的JSON文件供手动整合
|
|||
|
|
output = {}
|
|||
|
|
for position_name, questions_data in position_questions.items():
|
|||
|
|
output[position_name] = questions_data['all']
|
|||
|
|
|
|||
|
|
with open('visual_design_interview_questions.json', 'w', encoding='utf-8') as f:
|
|||
|
|
json.dump(output, f, ensure_ascii=False, indent=2)
|
|||
|
|
|
|||
|
|
print(f"已生成visual_design_interview_questions.json,包含{len(output)}个岗位的面试题数据")
|
|||
|
|
print("请手动将这些数据整合到resumeInterviewMock.js中对应岗位的questions字段")
|
|||
|
|
|
|||
|
|
if __name__ == '__main__':
|
|||
|
|
position_questions = process_visual_design_data()
|
|||
|
|
update_resume_interview_mock(position_questions)
|