93 lines
2.9 KiB
Python
93 lines
2.9 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
def load_visual_design_data():
|
|||
|
|
"""加载视觉设计岗位简历数据"""
|
|||
|
|
with open('网页未导入数据/视觉设计产业/视觉设计岗位简历.json', 'r', encoding='utf-8') as f:
|
|||
|
|
return json.load(f)
|
|||
|
|
|
|||
|
|
def extract_questions_from_content(content):
|
|||
|
|
"""从面试题内容中提取问题和答案"""
|
|||
|
|
questions = []
|
|||
|
|
|
|||
|
|
# 提取所有问题
|
|||
|
|
pattern = r'(\d+)\.\s*问题[::]?\s*(.*?)(?:\n\s*)?(?:参考回答[::]?)(.*?)(?=\d+\.\s*问题|$)'
|
|||
|
|
matches = re.findall(pattern, content, re.DOTALL)
|
|||
|
|
|
|||
|
|
for match in matches[:5]: # 限制为前5个问题
|
|||
|
|
q_num = match[0]
|
|||
|
|
question_text = match[1].strip()
|
|||
|
|
answer_text = match[2].strip()
|
|||
|
|
|
|||
|
|
questions.append({
|
|||
|
|
"id": f"q{q_num}",
|
|||
|
|
"question": question_text,
|
|||
|
|
"answer": answer_text
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
return questions
|
|||
|
|
|
|||
|
|
def update_mock_file():
|
|||
|
|
"""更新mock文件中的面试题数据"""
|
|||
|
|
|
|||
|
|
# 加载视觉设计数据
|
|||
|
|
visual_data = load_visual_design_data()
|
|||
|
|
|
|||
|
|
# 读取现有mock文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
mock_content = f.read()
|
|||
|
|
|
|||
|
|
# 查找摄影师的面试题
|
|||
|
|
questions = []
|
|||
|
|
for item in visual_data:
|
|||
|
|
if item.get('岗位名称') == '摄影师' and item.get('面试题内容'):
|
|||
|
|
questions = extract_questions_from_content(item.get('面试题内容', ''))
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
if not questions:
|
|||
|
|
print("⚠️ 未找到摄影师的面试题内容")
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
# 查找并替换摄影/摄像的questions
|
|||
|
|
pattern = r'("name":\s*"摄影/摄像".*?"questions":\s*\[)(.*?)(\]\s*\}}'
|
|||
|
|
|
|||
|
|
def replace_func(match):
|
|||
|
|
prefix = match.group(1)
|
|||
|
|
suffix = match.group(3)
|
|||
|
|
|
|||
|
|
# 构建新的questions数组
|
|||
|
|
questions_str = "\n"
|
|||
|
|
for i, q in enumerate(questions):
|
|||
|
|
if i > 0:
|
|||
|
|
questions_str += ",\n"
|
|||
|
|
|
|||
|
|
# 转义特殊字符
|
|||
|
|
question_escaped = q['question'].replace('\\', '\\\\').replace('"', '\\"')
|
|||
|
|
answer_escaped = q['answer'].replace('\\', '\\\\').replace('"', '\\"')
|
|||
|
|
|
|||
|
|
questions_str += f''' {{
|
|||
|
|
"id": "{q['id']}",
|
|||
|
|
"question": "{question_escaped}",
|
|||
|
|
"answer": "{answer_escaped}"
|
|||
|
|
}}'''
|
|||
|
|
|
|||
|
|
questions_str += "\n "
|
|||
|
|
|
|||
|
|
return prefix + questions_str + suffix
|
|||
|
|
|
|||
|
|
# 执行替换
|
|||
|
|
new_content = re.sub(pattern, replace_func, mock_content, count=1, flags=re.DOTALL)
|
|||
|
|
|
|||
|
|
if new_content != mock_content:
|
|||
|
|
# 写回文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(new_content)
|
|||
|
|
print(f"✓ 已更新岗位群:摄影/摄像 (使用岗位:摄影师,共{len(questions)}个面试题)")
|
|||
|
|
else:
|
|||
|
|
print("⚠️ 未能更新摄影/摄像岗位群")
|
|||
|
|
|
|||
|
|
if __name__ == '__main__':
|
|||
|
|
update_mock_file()
|