Files
ALL-teach_sys/frontend_视觉设计/test_single_update.py

93 lines
3.2 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
import json
import re
import os
# 只测试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_designer_questions = None
for position in positions_data:
if position.get("岗位名称") == "UI设计师":
interview_content = position.get("面试题内容", "")
if interview_content:
# 简化解析只提取前5个问题
questions = []
lines = interview_content.split('\n')
question_count = 0
for line in lines:
line = line.strip()
if line and line[0].isdigit() and '. ' in line and question_count < 5:
parts = line.split('. ', 1)
if len(parts) > 1:
question_text = parts[1].strip()
if question_text.startswith('问题:'):
question_text = question_text[3:].strip()
questions.append({
"id": f"q1_{question_count+1}",
"question": question_text,
"answer": "这是一个专业的UI设计问题需要根据实际项目经验回答。"
})
question_count += 1
ui_designer_questions = [{
"id": "group_q1",
"question": "# 专业能力类",
"subQuestions": questions
}]
break
if not ui_designer_questions:
print("未找到UI设计师面试题")
exit(1)
print(f"准备更新UI设计产业面试题{len(ui_designer_questions[0]['subQuestions'])}个问题")
# 读取文件
with open(mock_file, 'r', encoding='utf-8') as f:
content = f.read()
# 备份
backup_file = f"{mock_file}.backup_test_{os.popen('date +%Y%m%d_%H%M%S').read().strip()}"
with open(backup_file, 'w', encoding='utf-8') as f:
f.write(content)
print(f"已创建备份: {backup_file}")
# 生成JSON字符串
questions_str = json.dumps(ui_designer_questions, ensure_ascii=False, indent=8)
# 查找并替换UI设计的questions
pattern = r'("name":\s*"UI设计".*?"questions":\s*)\[[^\]]*?\](\s*[,}])'
match = re.search(pattern, content, re.DOTALL)
if match:
replacement = match.group(1) + questions_str + match.group(2)
new_content = re.sub(pattern, replacement, content, count=1, flags=re.DOTALL)
# 写入文件
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("✓ 语法验证通过")
else:
print("✗ 未找到UI设计产业")