250 lines
9.2 KiB
Python
250 lines
9.2 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)
|
|||
|
|
|
|||
|
|
# 创建产业到面试题的映射
|
|||
|
|
industry_questions = {}
|
|||
|
|
|
|||
|
|
# 产业名称映射
|
|||
|
|
industry_map = {
|
|||
|
|
"UI设计师": "UI设计",
|
|||
|
|
"包装设计师": "包装设计",
|
|||
|
|
"插画师": "插画设计",
|
|||
|
|
"影视灯光": "灯光",
|
|||
|
|
"角色原画师": "动画设计",
|
|||
|
|
"场景原画师": "动画设计",
|
|||
|
|
"二维动画师": "动画设计",
|
|||
|
|
"三维动画师": "动画设计",
|
|||
|
|
"三维动作师": "动画设计",
|
|||
|
|
"分镜绘制": "动画设计",
|
|||
|
|
"特效设计师": "后期特效",
|
|||
|
|
"后期合成": "后期特效",
|
|||
|
|
"剪辑师": "剪辑",
|
|||
|
|
"剪辑助理": "剪辑",
|
|||
|
|
"导演助理": "剪辑",
|
|||
|
|
"品牌视觉内容策划": "品牌设计",
|
|||
|
|
"品牌设计师": "品牌设计",
|
|||
|
|
"标志设计师": "品牌设计",
|
|||
|
|
"平面设计师": "平面设计",
|
|||
|
|
"书籍装帧设计师": "平面设计",
|
|||
|
|
"广告设计师": "平面设计",
|
|||
|
|
"3D建模师": "三维设计",
|
|||
|
|
"三维模型师": "三维设计",
|
|||
|
|
"三维材质师": "三维设计",
|
|||
|
|
"三维灯光师": "三维设计",
|
|||
|
|
"三维绑定师": "三维设计",
|
|||
|
|
"三维渲染师": "三维设计",
|
|||
|
|
"影视摄像": "摄影/摄像",
|
|||
|
|
"影视摄影": "摄影/摄像",
|
|||
|
|
"室内设计师": "室内设计",
|
|||
|
|
"调色师": "调色",
|
|||
|
|
"自媒体运营专员": "新媒体运营",
|
|||
|
|
"新媒体内容策划": "新媒体运营",
|
|||
|
|
"社交媒体运营": "新媒体运营",
|
|||
|
|
"音效设计师": "音频处理",
|
|||
|
|
"音频编辑师": "音频处理",
|
|||
|
|
"配音配乐师": "音频处理",
|
|||
|
|
"导演": "影视节目策划",
|
|||
|
|
"编剧": "影视节目策划",
|
|||
|
|
"直播运营": "直播",
|
|||
|
|
"直播策划": "直播",
|
|||
|
|
"主持人": "直播"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 提取每个岗位的面试题
|
|||
|
|
for position in positions_data:
|
|||
|
|
position_name = position.get("岗位名称", "")
|
|||
|
|
if position_name in industry_map:
|
|||
|
|
industry = industry_map[position_name]
|
|||
|
|
|
|||
|
|
# 提取面试题
|
|||
|
|
interview_content = position.get("面试题内容", "")
|
|||
|
|
if interview_content and industry not in industry_questions:
|
|||
|
|
questions = []
|
|||
|
|
lines = interview_content.split('\n')
|
|||
|
|
current_question = None
|
|||
|
|
current_answer = ''
|
|||
|
|
collecting_answer = False
|
|||
|
|
|
|||
|
|
for line in lines:
|
|||
|
|
line_stripped = line.strip()
|
|||
|
|
|
|||
|
|
# 检测问题行
|
|||
|
|
if line_stripped and line_stripped[0].isdigit() and '. 问题' in line_stripped:
|
|||
|
|
# 保存上一个问题
|
|||
|
|
if current_question:
|
|||
|
|
answer = current_answer.strip()
|
|||
|
|
if len(answer) > 400:
|
|||
|
|
cut_point = 400
|
|||
|
|
for sep in ['。', ';', '. ']:
|
|||
|
|
pos = answer[:400].rfind(sep)
|
|||
|
|
if pos > 200:
|
|||
|
|
cut_point = pos + 1
|
|||
|
|
break
|
|||
|
|
answer = answer[:cut_point]
|
|||
|
|
|
|||
|
|
questions.append({
|
|||
|
|
'question': current_question,
|
|||
|
|
'answer': answer if answer else "请根据您的实际经验和项目情况进行回答。"
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
# 提取新问题
|
|||
|
|
parts = line_stripped.split('问题:', 1)
|
|||
|
|
if len(parts) > 1:
|
|||
|
|
current_question = parts[1].strip()
|
|||
|
|
else:
|
|||
|
|
parts = line_stripped.split('问题:', 1)
|
|||
|
|
if len(parts) > 1:
|
|||
|
|
current_question = parts[1].strip()
|
|||
|
|
else:
|
|||
|
|
# 尝试其他格式
|
|||
|
|
parts = line_stripped.split('. ', 1)
|
|||
|
|
if len(parts) > 1:
|
|||
|
|
current_question = parts[1].strip()
|
|||
|
|
|
|||
|
|
current_answer = ''
|
|||
|
|
collecting_answer = False
|
|||
|
|
|
|||
|
|
# 检测答案开始
|
|||
|
|
elif any(marker in line for marker in ['参考回答:', '参考答案:', '答案:']):
|
|||
|
|
collecting_answer = True
|
|||
|
|
for marker in ['参考回答:', '参考答案:', '答案:']:
|
|||
|
|
if marker in line:
|
|||
|
|
answer_part = line.split(marker, 1)[1].strip()
|
|||
|
|
if answer_part:
|
|||
|
|
current_answer = answer_part
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 收集答案内容
|
|||
|
|
elif collecting_answer and line.strip():
|
|||
|
|
if (line_stripped and line_stripped[0].isdigit() and '. 问题' in line_stripped) or line_stripped.startswith('#'):
|
|||
|
|
collecting_answer = False
|
|||
|
|
else:
|
|||
|
|
if current_answer:
|
|||
|
|
current_answer += ' '
|
|||
|
|
current_answer += line.strip()
|
|||
|
|
|
|||
|
|
# 保存最后一个问题
|
|||
|
|
if current_question:
|
|||
|
|
answer = current_answer.strip()
|
|||
|
|
if len(answer) > 400:
|
|||
|
|
cut_point = 400
|
|||
|
|
for sep in ['。', ';', '. ']:
|
|||
|
|
pos = answer[:400].rfind(sep)
|
|||
|
|
if pos > 200:
|
|||
|
|
cut_point = pos + 1
|
|||
|
|
break
|
|||
|
|
answer = answer[:cut_point]
|
|||
|
|
|
|||
|
|
questions.append({
|
|||
|
|
'question': current_question,
|
|||
|
|
'answer': answer if answer else "请根据您的实际经验和项目情况进行回答。"
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
if questions:
|
|||
|
|
industry_questions[industry] = questions
|
|||
|
|
print(f"提取了 {industry} 的 {len(questions)} 个问题")
|
|||
|
|
|
|||
|
|
# 读取现有文件
|
|||
|
|
with open(mock_file, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 创建备份
|
|||
|
|
backup_file = f"{mock_file}.backup_all_industries_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
|||
|
|
with open(backup_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print(f"\n已创建备份:{backup_file}")
|
|||
|
|
|
|||
|
|
# 更新每个产业的questions字段
|
|||
|
|
print("\n开始更新所有产业的面试题...")
|
|||
|
|
updated_count = 0
|
|||
|
|
|
|||
|
|
for industry, questions in industry_questions.items():
|
|||
|
|
if industry == "UI设计":
|
|||
|
|
# UI设计已经更新过了
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 构建新的questions数组
|
|||
|
|
sub_questions = []
|
|||
|
|
for i, qa in enumerate(questions, 1):
|
|||
|
|
question_text = qa['question'].replace('"', '\\"')
|
|||
|
|
answer_text = qa['answer'].replace('"', '\\"').replace('\n', ' ')
|
|||
|
|
|
|||
|
|
sub_questions.append({
|
|||
|
|
"id": f"q{updated_count+2}_{i}",
|
|||
|
|
"question": question_text,
|
|||
|
|
"answer": answer_text
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
# 查找产业位置
|
|||
|
|
pattern = rf'"name":\s*"{re.escape(industry)}".*?"questions":\s*\['
|
|||
|
|
match = re.search(pattern, content, re.DOTALL)
|
|||
|
|
|
|||
|
|
if match:
|
|||
|
|
# 找到questions数组的结束位置
|
|||
|
|
start_pos = match.end()
|
|||
|
|
bracket_count = 1
|
|||
|
|
end_pos = start_pos
|
|||
|
|
|
|||
|
|
while bracket_count > 0 and end_pos < len(content):
|
|||
|
|
if content[end_pos] == '[':
|
|||
|
|
bracket_count += 1
|
|||
|
|
elif content[end_pos] == ']':
|
|||
|
|
bracket_count -= 1
|
|||
|
|
end_pos += 1
|
|||
|
|
|
|||
|
|
if bracket_count == 0:
|
|||
|
|
# 构建新的questions内容
|
|||
|
|
new_questions = [{
|
|||
|
|
"id": f"group_q{updated_count+2}",
|
|||
|
|
"question": f"# {industry}面试题",
|
|||
|
|
"subQuestions": sub_questions
|
|||
|
|
}]
|
|||
|
|
|
|||
|
|
# 转换为JSON字符串
|
|||
|
|
questions_str = json.dumps(new_questions, ensure_ascii=False, indent=6)
|
|||
|
|
# 调整缩进
|
|||
|
|
questions_str = '\n'.join([' ' + line if line.strip() else line
|
|||
|
|
for line in questions_str.split('\n')])
|
|||
|
|
|
|||
|
|
# 替换内容
|
|||
|
|
content = content[:match.end()-1] + questions_str + content[end_pos-1:]
|
|||
|
|
updated_count += 1
|
|||
|
|
print(f"✓ 更新了 {industry} 的 {len(sub_questions)} 个问题")
|
|||
|
|
else:
|
|||
|
|
print(f"✗ 未能正确解析 {industry} 的questions数组")
|
|||
|
|
else:
|
|||
|
|
print(f"✗ 未找到产业:{industry}")
|
|||
|
|
|
|||
|
|
# 写入文件
|
|||
|
|
if updated_count > 0:
|
|||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
# 验证语法
|
|||
|
|
print(f"\n验证语法...")
|
|||
|
|
result = os.popen(f'node -c {mock_file} 2>&1').read()
|
|||
|
|
if result:
|
|||
|
|
print(f"❌ 语法错误:{result}")
|
|||
|
|
# 恢复备份
|
|||
|
|
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(f"\n成功更新 {updated_count} 个产业的面试题!")
|
|||
|
|
print("所有视觉设计产业的面试题已更新为完整版本。")
|
|||
|
|
else:
|
|||
|
|
print("\n未能更新任何产业")
|