182 lines
6.3 KiB
Python
182 lines
6.3 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
import json
|
|||
|
|
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)
|
|||
|
|
|
|||
|
|
# 解析所有岗位的面试题
|
|||
|
|
all_questions = {}
|
|||
|
|
for position in positions_data:
|
|||
|
|
position_name = position.get("岗位名称", "")
|
|||
|
|
interview_content = position.get("面试题内容", "")
|
|||
|
|
if position_name and interview_content:
|
|||
|
|
questions = []
|
|||
|
|
lines = interview_content.split('\n')
|
|||
|
|
current_section = "专业能力类" # 默认分类
|
|||
|
|
|
|||
|
|
for line in lines:
|
|||
|
|
line = line.strip()
|
|||
|
|
# 识别大分类
|
|||
|
|
if line.startswith('# '):
|
|||
|
|
section_text = line[2:].strip()
|
|||
|
|
if '专业' in section_text or '能力' in section_text:
|
|||
|
|
current_section = "专业能力类"
|
|||
|
|
elif '行为' in section_text or '经历' in section_text:
|
|||
|
|
current_section = "行为经历类"
|
|||
|
|
elif '情景' in section_text or '应变' in section_text:
|
|||
|
|
current_section = "情景应变类"
|
|||
|
|
else:
|
|||
|
|
current_section = section_text
|
|||
|
|
|
|||
|
|
# 识别问题
|
|||
|
|
elif line and line[0].isdigit() and '. 问题' in line:
|
|||
|
|
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:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
questions.append({
|
|||
|
|
"question": question_text,
|
|||
|
|
"section": current_section
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
all_questions[position_name] = questions
|
|||
|
|
if questions:
|
|||
|
|
print(f"解析 {position_name}:{len(questions)} 个问题")
|
|||
|
|
|
|||
|
|
# 创建备份
|
|||
|
|
backup_file = f"{mock_file}.backup_direct_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
|||
|
|
with open(mock_file, 'r', encoding='utf-8') as f:
|
|||
|
|
original_content = f.read()
|
|||
|
|
with open(backup_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(original_content)
|
|||
|
|
print(f"\n已创建备份:{backup_file}")
|
|||
|
|
|
|||
|
|
# 定义产业和岗位的映射
|
|||
|
|
industry_map = {
|
|||
|
|
"UI设计": "UI设计师",
|
|||
|
|
"包装设计": "包装设计师",
|
|||
|
|
"插画设计": "插画师",
|
|||
|
|
"灯光": "影视灯光",
|
|||
|
|
"动画设计": "动画师",
|
|||
|
|
"后期特效": "特效设计师",
|
|||
|
|
"剪辑": "剪辑师",
|
|||
|
|
"品牌设计": "品牌视觉内容策划",
|
|||
|
|
"平面设计": "平面设计师",
|
|||
|
|
"三维设计": "3D建模师",
|
|||
|
|
"摄影/摄像": "摄影师",
|
|||
|
|
"室内设计": "室内设计师",
|
|||
|
|
"调色": "调色师",
|
|||
|
|
"新媒体运营": "新媒体运营专员",
|
|||
|
|
"音频处理": "音效设计师",
|
|||
|
|
"影视节目策划": "导演",
|
|||
|
|
"直播": "直播助理"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 更新面试题
|
|||
|
|
print("\n开始更新面试题...")
|
|||
|
|
content = original_content
|
|||
|
|
update_count = 0
|
|||
|
|
|
|||
|
|
for industry_name, position_name in industry_map.items():
|
|||
|
|
if position_name not in all_questions:
|
|||
|
|
print(f"✗ 未找到 {position_name} 的面试题数据")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
questions = all_questions[position_name]
|
|||
|
|
if not questions:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 按分类组织问题
|
|||
|
|
sections = {}
|
|||
|
|
for q in questions:
|
|||
|
|
section = q['section']
|
|||
|
|
if section not in sections:
|
|||
|
|
sections[section] = []
|
|||
|
|
sections[section].append(q['question'])
|
|||
|
|
|
|||
|
|
# 构建新的questions数组
|
|||
|
|
new_questions = []
|
|||
|
|
group_id = 1
|
|||
|
|
for section_name, section_questions in sections.items():
|
|||
|
|
if section_questions:
|
|||
|
|
group = {
|
|||
|
|
"id": f"group_q{group_id}",
|
|||
|
|
"question": f"# {section_name}",
|
|||
|
|
"subQuestions": []
|
|||
|
|
}
|
|||
|
|
for idx, q_text in enumerate(section_questions, 1):
|
|||
|
|
group["subQuestions"].append({
|
|||
|
|
"id": f"q{group_id}_{idx}",
|
|||
|
|
"question": q_text,
|
|||
|
|
"answer": "请根据您的实际经验和项目情况,结合专业知识进行回答。"
|
|||
|
|
})
|
|||
|
|
new_questions.append(group)
|
|||
|
|
group_id += 1
|
|||
|
|
|
|||
|
|
# 生成JSON字符串
|
|||
|
|
questions_json = json.dumps(new_questions, ensure_ascii=False, indent=6)
|
|||
|
|
|
|||
|
|
# 查找并替换
|
|||
|
|
# 搜索产业名称
|
|||
|
|
search_str = f'"name": "{industry_name}"'
|
|||
|
|
if search_str in content:
|
|||
|
|
# 找到产业位置
|
|||
|
|
start_idx = content.find(search_str)
|
|||
|
|
|
|||
|
|
# 找到对应的questions字段
|
|||
|
|
questions_start = content.find('"questions":', start_idx)
|
|||
|
|
if questions_start > 0 and questions_start < start_idx + 2000: # 确保在同一产业内
|
|||
|
|
# 找到questions数组的开始 [
|
|||
|
|
array_start = content.find('[', questions_start)
|
|||
|
|
if array_start > 0:
|
|||
|
|
# 找到对应的结束 ]
|
|||
|
|
bracket_count = 1
|
|||
|
|
idx = array_start + 1
|
|||
|
|
while idx < len(content) and bracket_count > 0:
|
|||
|
|
if content[idx] == '[':
|
|||
|
|
bracket_count += 1
|
|||
|
|
elif content[idx] == ']':
|
|||
|
|
bracket_count -= 1
|
|||
|
|
idx += 1
|
|||
|
|
|
|||
|
|
if bracket_count == 0:
|
|||
|
|
# 替换questions内容
|
|||
|
|
content = content[:array_start] + questions_json + content[idx-1:]
|
|||
|
|
update_count += 1
|
|||
|
|
print(f"✓ 已更新 {industry_name} ({len(questions)} 个问题)")
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
if update_count > 0:
|
|||
|
|
print(f"\n正在写入文件...")
|
|||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
# 验证语法
|
|||
|
|
print("验证文件语法...")
|
|||
|
|
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成功更新 {update_count} 个产业的面试题!")
|
|||
|
|
else:
|
|||
|
|
print("\n未更新任何产业")
|