209 lines
8.3 KiB
Python
209 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:].strip()
|
||
|
|
elif line and line[0].isdigit() and '. 问题' in line:
|
||
|
|
# 保存上一个问题
|
||
|
|
if current_question:
|
||
|
|
questions.append(current_question)
|
||
|
|
|
||
|
|
# 提取问题文本
|
||
|
|
parts = line.split('问题:', 1)
|
||
|
|
if len(parts) > 1:
|
||
|
|
question_text = parts[1].strip()
|
||
|
|
else:
|
||
|
|
parts = line.split('问题:', 1)
|
||
|
|
if len(parts) > 1:
|
||
|
|
question_text = parts[1].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.replace('答案:', '').replace('答案:', '').strip()
|
||
|
|
current_question["answer"] = answer
|
||
|
|
elif current_question and line and not line.startswith('#') and not (line[0].isdigit() and '. 问题' in line):
|
||
|
|
# 继续添加到答案中(多行答案)
|
||
|
|
if current_question["answer"] and not line.startswith('---'):
|
||
|
|
current_question["answer"] += " " + line
|
||
|
|
|
||
|
|
# 添加最后一个问题
|
||
|
|
if current_question:
|
||
|
|
questions.append(current_question)
|
||
|
|
|
||
|
|
interview_questions_map[position_name] = questions
|
||
|
|
if 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_complete_{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 = []
|
||
|
|
|
||
|
|
for section_name, section_questions in sections.items():
|
||
|
|
if section_questions:
|
||
|
|
# 创建分组
|
||
|
|
group = {
|
||
|
|
"id": f"group_q{len(result)+1}",
|
||
|
|
"question": f"# {section_name}" if section_name else "# 面试题",
|
||
|
|
"subQuestions": []
|
||
|
|
}
|
||
|
|
|
||
|
|
for idx, q in enumerate(section_questions):
|
||
|
|
sub_q = {
|
||
|
|
"id": f"q{len(result)+1}_{idx+1}",
|
||
|
|
"question": q["question"],
|
||
|
|
"answer": q["answer"] if q["answer"] else "请根据实际情况回答。"
|
||
|
|
}
|
||
|
|
group["subQuestions"].append(sub_q)
|
||
|
|
|
||
|
|
if group["subQuestions"]: # 只添加有内容的分组
|
||
|
|
result.append(group)
|
||
|
|
|
||
|
|
return result
|
||
|
|
|
||
|
|
# 定义产业和岗位的映射关系
|
||
|
|
industry_positions_map = {
|
||
|
|
"UI设计": ["UI设计师"],
|
||
|
|
"包装设计": ["包装设计师"],
|
||
|
|
"插画设计": ["插画师"],
|
||
|
|
"灯光": ["影视灯光"],
|
||
|
|
"动画设计": ["动画师", "角色原画师", "分镜设计师"],
|
||
|
|
"后期特效": ["特效设计师", "3D特效师", "特效合成师", "CG总监助理"],
|
||
|
|
"剪辑": ["剪辑师", "影视剪辑", "短视频剪辑师"],
|
||
|
|
"品牌设计": ["品牌视觉内容策划", "LOGO设计师", "品牌视觉传播策划管培生"],
|
||
|
|
"平面设计": ["平面设计师", "AIGC设计师", "AI绘画师"],
|
||
|
|
"三维设计": ["3D建模师", "渲染合成师", "材质灯光师", "游戏场景地编", "游戏场景生态设计师助理", "潮玩设计师"],
|
||
|
|
"摄影/摄像": ["摄影师", "影视摄像", "摄影美术指导助理"],
|
||
|
|
"室内设计": ["室内设计师", "美术总监助理"],
|
||
|
|
"调色": ["调色师"],
|
||
|
|
"新媒体运营": ["新媒体运营专员", "自媒体运营专员"],
|
||
|
|
"音频处理": ["音效设计师", "音频编辑师", "混音师", "录音师"],
|
||
|
|
"影视节目策划": ["导演", "文案策划"],
|
||
|
|
"直播": ["社群运营", "直播助理", "直播运营", "直播专员"]
|
||
|
|
}
|
||
|
|
|
||
|
|
# 更新industries中的questions字段
|
||
|
|
print("\n开始更新面试题数据...")
|
||
|
|
update_count = 0
|
||
|
|
failed_industries = []
|
||
|
|
|
||
|
|
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]
|
||
|
|
if not questions:
|
||
|
|
continue
|
||
|
|
|
||
|
|
questions_data = create_industry_questions(position_name, questions)
|
||
|
|
if not questions_data:
|
||
|
|
continue
|
||
|
|
|
||
|
|
questions_str = json.dumps(questions_data, ensure_ascii=False, indent=6)
|
||
|
|
|
||
|
|
# 转义特殊字符
|
||
|
|
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:
|
||
|
|
# 保留后续的逗号或大括号
|
||
|
|
full_pattern = r'("name":\s*"' + escaped_name + r'"[^}]*?"questions":\s*)\[[^\]]*?\](\s*[,}])'
|
||
|
|
full_match = re.search(full_pattern, content, re.DOTALL)
|
||
|
|
|
||
|
|
if full_match:
|
||
|
|
replacement = full_match.group(1) + questions_str + full_match.group(2)
|
||
|
|
content = re.sub(full_pattern, replacement, content, count=1, flags=re.DOTALL)
|
||
|
|
update_count += 1
|
||
|
|
print(f"✓ 已更新 {industry_name} 产业的面试题({len(questions)} 个问题)")
|
||
|
|
else:
|
||
|
|
failed_industries.append(industry_name)
|
||
|
|
print(f"✗ 未找到 {industry_name} 产业的完整questions字段")
|
||
|
|
else:
|
||
|
|
failed_industries.append(industry_name)
|
||
|
|
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} 个产业的面试题")
|
||
|
|
if failed_industries:
|
||
|
|
print(f"失败的产业: {', '.join(failed_industries)}")
|
||
|
|
|
||
|
|
# 验证语法
|
||
|
|
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("✓ 语法验证通过")
|
||
|
|
print("\n面试题更新成功!现在每个产业都有完整的面试题数据。")
|