123 lines
4.1 KiB
Python
123 lines
4.1 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
import json
|
|||
|
|
import os
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
# 读取视觉设计岗位简历.json文件获取UI设计师的完整面试题
|
|||
|
|
json_file = '网页未导入数据/视觉设计产业/视觉设计岗位简历.json'
|
|||
|
|
mock_file = 'src/mocks/resumeInterviewMock.js'
|
|||
|
|
|
|||
|
|
print("正在读取UI设计师的完整面试题数据...")
|
|||
|
|
with open(json_file, 'r', encoding='utf-8') as f:
|
|||
|
|
positions_data = json.load(f)
|
|||
|
|
|
|||
|
|
# 找到UI设计师的面试题
|
|||
|
|
ui_questions = []
|
|||
|
|
for position in positions_data:
|
|||
|
|
if position.get("岗位名称") == "UI设计师":
|
|||
|
|
interview_content = position.get("面试题内容", "")
|
|||
|
|
lines = interview_content.split('\n')
|
|||
|
|
|
|||
|
|
for line in lines:
|
|||
|
|
line = line.strip()
|
|||
|
|
if line and line[0].isdigit() and '. 问题' in line:
|
|||
|
|
parts = line.split('问题:', 1)
|
|||
|
|
if len(parts) > 1:
|
|||
|
|
question_text = parts[1].strip()
|
|||
|
|
ui_questions.append(question_text)
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
print(f"找到 {len(ui_questions)} 个UI设计师面试题")
|
|||
|
|
|
|||
|
|
# 创建备份
|
|||
|
|
backup_file = f"{mock_file}.backup_precise_{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"已创建备份:{backup_file}")
|
|||
|
|
|
|||
|
|
# 构建新的questions数组(只更新UI设计)
|
|||
|
|
new_questions = [
|
|||
|
|
{
|
|||
|
|
"id": "group_q1",
|
|||
|
|
"question": "# 一、专业能力类",
|
|||
|
|
"subQuestions": []
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "group_q2",
|
|||
|
|
"question": "# 二、行为经历类",
|
|||
|
|
"subQuestions": []
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "group_q3",
|
|||
|
|
"question": "# 三、情景应变类",
|
|||
|
|
"subQuestions": []
|
|||
|
|
}
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
# 分配问题到不同分类
|
|||
|
|
for idx, q in enumerate(ui_questions, 1):
|
|||
|
|
if idx <= 5: # 前5个为专业能力类
|
|||
|
|
group_idx = 0
|
|||
|
|
sub_idx = len(new_questions[0]["subQuestions"]) + 1
|
|||
|
|
q_id = f"q1_{sub_idx}"
|
|||
|
|
elif idx <= 10: # 6-10为行为经历类
|
|||
|
|
group_idx = 1
|
|||
|
|
sub_idx = len(new_questions[1]["subQuestions"]) + 1
|
|||
|
|
q_id = f"q2_{sub_idx}"
|
|||
|
|
else: # 11以后为情景应变类
|
|||
|
|
group_idx = 2
|
|||
|
|
sub_idx = len(new_questions[2]["subQuestions"]) + 1
|
|||
|
|
q_id = f"q3_{sub_idx}"
|
|||
|
|
|
|||
|
|
new_questions[group_idx]["subQuestions"].append({
|
|||
|
|
"id": q_id,
|
|||
|
|
"question": q,
|
|||
|
|
"answer": "请根据您的实际经验和项目情况,结合专业知识进行回答。"
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
# 生成格式化的JSON字符串
|
|||
|
|
questions_json = json.dumps(new_questions, ensure_ascii=False, indent=6)
|
|||
|
|
|
|||
|
|
# 替换UI设计产业的questions
|
|||
|
|
# 找到UI设计的questions位置
|
|||
|
|
ui_start = original_content.find('"name": "UI设计"')
|
|||
|
|
if ui_start > 0:
|
|||
|
|
# 找到questions字段
|
|||
|
|
q_start = original_content.find('"questions":', ui_start)
|
|||
|
|
if q_start > 0 and q_start < ui_start + 1000:
|
|||
|
|
# 找到数组开始
|
|||
|
|
arr_start = original_content.find('[', q_start)
|
|||
|
|
# 找到对应的结束]
|
|||
|
|
bracket_count = 1
|
|||
|
|
idx = arr_start + 1
|
|||
|
|
while idx < len(original_content) and bracket_count > 0:
|
|||
|
|
if original_content[idx] == '[':
|
|||
|
|
bracket_count += 1
|
|||
|
|
elif original_content[idx] == ']':
|
|||
|
|
bracket_count -= 1
|
|||
|
|
idx += 1
|
|||
|
|
|
|||
|
|
# 替换内容
|
|||
|
|
new_content = original_content[:arr_start] + questions_json + original_content[idx-1:]
|
|||
|
|
|
|||
|
|
# 写入文件
|
|||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(new_content)
|
|||
|
|
|
|||
|
|
print("已更新UI设计产业的面试题")
|
|||
|
|
|
|||
|
|
# 验证语法
|
|||
|
|
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("\nUI设计产业的面试题已成功更新为完整数据!")
|