207 lines
8.3 KiB
Python
207 lines
8.3 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
import os
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
# 读取视觉设计岗位简历.json文件
|
|||
|
|
json_file = '网页未导入数据/视觉设计产业/视觉设计岗位简历.json'
|
|||
|
|
mock_file = 'src/mocks/resumeInterviewMock.js'
|
|||
|
|
|
|||
|
|
print("正在读取面试题数据...")
|
|||
|
|
with open(json_file, 'r', encoding='utf-8') as f:
|
|||
|
|
positions_data = json.load(f)
|
|||
|
|
|
|||
|
|
# 创建岗位名称到面试题的映射
|
|||
|
|
interview_questions_map = {}
|
|||
|
|
for position in positions_data:
|
|||
|
|
position_name = position.get("岗位名称", "")
|
|||
|
|
interview_content = position.get("面试题内容", "")
|
|||
|
|
if position_name and interview_content:
|
|||
|
|
# 解析markdown格式的面试题
|
|||
|
|
questions = []
|
|||
|
|
lines = interview_content.split('\n')
|
|||
|
|
current_section = ""
|
|||
|
|
current_question = None
|
|||
|
|
|
|||
|
|
for line in lines:
|
|||
|
|
line = line.strip()
|
|||
|
|
if line.startswith('# '):
|
|||
|
|
current_section = line[2:]
|
|||
|
|
elif line.startswith('## ') or (line and line[0].isdigit() and '. ' in line):
|
|||
|
|
# 新问题
|
|||
|
|
if current_question:
|
|||
|
|
questions.append(current_question)
|
|||
|
|
|
|||
|
|
# 提取问题文本
|
|||
|
|
if line.startswith('## '):
|
|||
|
|
question_text = line[3:]
|
|||
|
|
else:
|
|||
|
|
# 处理数字编号的问题
|
|||
|
|
parts = line.split('. ', 1)
|
|||
|
|
if len(parts) > 1:
|
|||
|
|
question_text = parts[1].strip()
|
|||
|
|
# 移除"问题:"前缀
|
|||
|
|
if question_text.startswith('问题:'):
|
|||
|
|
question_text = question_text[3:].strip()
|
|||
|
|
elif question_text.startswith('问题:'):
|
|||
|
|
question_text = question_text[3:].strip()
|
|||
|
|
else:
|
|||
|
|
question_text = line
|
|||
|
|
|
|||
|
|
current_question = {
|
|||
|
|
"question": question_text,
|
|||
|
|
"answer": "",
|
|||
|
|
"section": current_section
|
|||
|
|
}
|
|||
|
|
elif line.startswith('答案:') or line.startswith('答案:'):
|
|||
|
|
if current_question:
|
|||
|
|
answer = line[3:].strip()
|
|||
|
|
current_question["answer"] = answer
|
|||
|
|
elif current_question and line and not line.startswith('#'):
|
|||
|
|
# 继续添加到答案中
|
|||
|
|
if current_question["answer"]:
|
|||
|
|
current_question["answer"] += " " + line
|
|||
|
|
|
|||
|
|
# 添加最后一个问题
|
|||
|
|
if current_question:
|
|||
|
|
questions.append(current_question)
|
|||
|
|
|
|||
|
|
interview_questions_map[position_name] = questions
|
|||
|
|
print(f"解析 {position_name} 的面试题,共 {len(questions)} 个问题")
|
|||
|
|
|
|||
|
|
print(f"\n总共找到 {len(interview_questions_map)} 个岗位的面试题")
|
|||
|
|
|
|||
|
|
# 读取resumeInterviewMock.js文件
|
|||
|
|
print("\n正在读取 resumeInterviewMock.js...")
|
|||
|
|
with open(mock_file, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 创建备份
|
|||
|
|
backup_file = f"{mock_file}.backup_interview_modal_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
|||
|
|
with open(backup_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print(f"已创建备份文件: {backup_file}")
|
|||
|
|
|
|||
|
|
# 为每个产业创建面试题数据
|
|||
|
|
def create_industry_questions(position_name, questions):
|
|||
|
|
"""为特定岗位创建面试题数组"""
|
|||
|
|
# 按section分组
|
|||
|
|
sections = {}
|
|||
|
|
for q in questions:
|
|||
|
|
section = q.get('section', '通用问题')
|
|||
|
|
if section not in sections:
|
|||
|
|
sections[section] = []
|
|||
|
|
sections[section].append(q)
|
|||
|
|
|
|||
|
|
# 创建questions数组
|
|||
|
|
result = []
|
|||
|
|
question_id = 1
|
|||
|
|
|
|||
|
|
for section_name, section_questions in sections.items():
|
|||
|
|
if section_questions:
|
|||
|
|
# 创建分组
|
|||
|
|
group = {
|
|||
|
|
"id": f"group_q{len(result)+1}",
|
|||
|
|
"question": f"# {section_name}",
|
|||
|
|
"subQuestions": []
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for q in section_questions:
|
|||
|
|
group["subQuestions"].append({
|
|||
|
|
"id": f"q{len(result)+1}_{len(group['subQuestions'])+1}",
|
|||
|
|
"question": q["question"],
|
|||
|
|
"answer": q["answer"] if q["answer"] else "请根据实际情况回答。"
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
result.append(group)
|
|||
|
|
|
|||
|
|
return result
|
|||
|
|
|
|||
|
|
# 更新industries中的questions字段
|
|||
|
|
print("\n开始更新面试题数据...")
|
|||
|
|
update_count = 0
|
|||
|
|
|
|||
|
|
# 定义产业和岗位的映射关系
|
|||
|
|
industry_positions_map = {
|
|||
|
|
"UI设计": ["UI设计师"],
|
|||
|
|
"包装设计": ["包装设计师"],
|
|||
|
|
"插画设计": ["插画师"],
|
|||
|
|
"灯光": ["影视灯光"],
|
|||
|
|
"动画设计": ["动画师", "角色原画师", "分镜设计师"],
|
|||
|
|
"后期特效": ["特效设计师", "3D特效师", "特效合成师", "CG总监助理"],
|
|||
|
|
"剪辑": ["剪辑师", "影视剪辑", "短视频剪辑师"],
|
|||
|
|
"品牌设计": ["品牌视觉内容策划", "LOGO设计师", "品牌视觉传播策划管培生"],
|
|||
|
|
"平面设计": ["平面设计师", "AIGC设计师", "AI绘画师"],
|
|||
|
|
"三维设计": ["3D建模师", "渲染合成师", "材质灯光师", "游戏场景地编", "游戏场景生态设计师助理", "潮玩设计师"],
|
|||
|
|
"摄影/摄像": ["摄影师", "影视摄像", "摄影美术指导助理"],
|
|||
|
|
"室内设计": ["室内设计师", "美术总监助理"],
|
|||
|
|
"调色": ["调色师"],
|
|||
|
|
"新媒体运营": ["新媒体运营专员"],
|
|||
|
|
"音频处理": ["音效设计师", "音频编辑师", "混音师", "录音师"],
|
|||
|
|
"影视节目策划": ["导演", "文案策划"],
|
|||
|
|
"直播": ["社群运营", "直播助理"]
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 为每个产业更新面试题
|
|||
|
|
for industry_name, position_names in industry_positions_map.items():
|
|||
|
|
# 获取该产业下第一个岗位的面试题作为产业面试题
|
|||
|
|
for position_name in position_names:
|
|||
|
|
if position_name in interview_questions_map:
|
|||
|
|
questions = interview_questions_map[position_name]
|
|||
|
|
questions_str = json.dumps(
|
|||
|
|
create_industry_questions(position_name, questions),
|
|||
|
|
ensure_ascii=False,
|
|||
|
|
indent=4
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 转义特殊字符用于正则表达式
|
|||
|
|
escaped_name = re.escape(industry_name)
|
|||
|
|
|
|||
|
|
# 查找该产业并替换其questions字段
|
|||
|
|
# 使用更灵活的正则表达式,处理可能的格式差异
|
|||
|
|
pattern = r'("name":\s*"' + escaped_name + r'".*?"questions":\s*)\[[^\]]*?\]'
|
|||
|
|
|
|||
|
|
match = re.search(pattern, content, re.DOTALL)
|
|||
|
|
if match:
|
|||
|
|
# 查找替换后的内容,确保格式正确
|
|||
|
|
# 检查questions数组后是否有逗号或结束符
|
|||
|
|
full_pattern = r'("name":\s*"' + escaped_name + r'".*?"questions":\s*)\[[^\]]*?\](\s*[,}])'
|
|||
|
|
full_match = re.search(full_pattern, content, re.DOTALL)
|
|||
|
|
|
|||
|
|
if full_match:
|
|||
|
|
# 替换questions数组,保留后续的逗号或结束符
|
|||
|
|
replacement = full_match.group(1) + questions_str + full_match.group(2)
|
|||
|
|
content = re.sub(full_pattern, replacement, content, count=1, flags=re.DOTALL)
|
|||
|
|
else:
|
|||
|
|
# 如果没有找到完整匹配,使用原方案
|
|||
|
|
replacement = match.group(1) + questions_str
|
|||
|
|
content = re.sub(pattern, replacement, content, count=1, flags=re.DOTALL)
|
|||
|
|
update_count += 1
|
|||
|
|
print(f"✓ 已更新 {industry_name} 产业的面试题")
|
|||
|
|
else:
|
|||
|
|
print(f"✗ 未找到 {industry_name} 产业的questions字段")
|
|||
|
|
break # 只使用第一个找到的岗位面试题
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
print(f"\n正在写入更新后的内容...")
|
|||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
print(f"\n更新完成!")
|
|||
|
|
print(f"成功更新: {update_count} 个产业的面试题")
|
|||
|
|
|
|||
|
|
# 验证语法
|
|||
|
|
print("\n验证文件语法...")
|
|||
|
|
result = os.popen(f'node -c {mock_file} 2>&1').read()
|
|||
|
|
if result:
|
|||
|
|
print(f"❌ 语法错误: {result}")
|
|||
|
|
# 恢复备份
|
|||
|
|
print("正在恢复备份...")
|
|||
|
|
with open(backup_file, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print("已恢复备份文件")
|
|||
|
|
else:
|
|||
|
|
print("✓ 语法验证通过")
|