- 包含4个产业方向的前端项目:智能开发、智能制造、大健康、财经商贸 - 已清理node_modules、.yoyo等大文件,项目大小从2.6GB优化至631MB - 配置完善的.gitignore文件 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
104 lines
3.6 KiB
Python
104 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
import re
|
|
from datetime import datetime
|
|
|
|
# 读取mock文件
|
|
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# 备份原文件
|
|
backup_time = datetime.now().strftime('%Y%m%d_%H%M%S')
|
|
with open(f'src/mocks/resumeInterviewMock.js.backup_final_{backup_time}', 'w', encoding='utf-8') as f:
|
|
f.write(content)
|
|
print(f"已创建备份文件: src/mocks/resumeInterviewMock.js.backup_final_{backup_time}")
|
|
|
|
def merge_questions(match):
|
|
"""合并questions数组中的所有题目到一个对象"""
|
|
full_match = match.group(0)
|
|
questions_content = match.group(1)
|
|
|
|
# 提取所有的subQuestions
|
|
all_sub_questions = []
|
|
|
|
# 查找所有的subQuestions数组
|
|
sub_pattern = r'"subQuestions":\s*\[(.*?)\](?=\s*\})'
|
|
sub_matches = re.finditer(sub_pattern, questions_content, re.DOTALL)
|
|
|
|
question_counter = 1
|
|
for sub_match in sub_matches:
|
|
sub_content = sub_match.group(1)
|
|
|
|
# 提取每个问题和答案
|
|
q_pattern = r'"id":\s*"[^"]+",\s*"question":\s*"([^"\\]*(?:\\.[^"\\]*)*)",\s*"answer":\s*"([^"\\]*(?:\\.[^"\\]*)*)"'
|
|
q_matches = re.finditer(q_pattern, sub_content)
|
|
|
|
for q_match in q_matches:
|
|
question = q_match.group(1)
|
|
answer = q_match.group(2)
|
|
|
|
# 处理答案格式
|
|
if len(answer.strip()) == 1 and answer.strip() in 'ABCDEFGH':
|
|
# 选择题单字母答案
|
|
formatted_answer = answer
|
|
else:
|
|
# 处理换行
|
|
formatted_answer = answer.replace('\\n', '<br/>')
|
|
# 移除选项标记(如 A. B. C.)
|
|
formatted_answer = re.sub(r'\\s*[A-H]\\.\\s*', '', formatted_answer)
|
|
|
|
all_sub_questions.append({
|
|
'id': f'q_{question_counter}',
|
|
'question': question,
|
|
'answer': formatted_answer
|
|
})
|
|
question_counter += 1
|
|
|
|
# 构建新的questions数组
|
|
result = '"questions": [\n {\n'
|
|
result += ' "id": "all_questions",\n'
|
|
result += ' "question": "面试题集",\n'
|
|
result += ' "subQuestions": [\n'
|
|
|
|
for i, q in enumerate(all_sub_questions):
|
|
# 确保引号被正确转义
|
|
question_str = q['question'].replace('\\', '\\\\').replace('"', '\\"')
|
|
answer_str = q['answer'].replace('\\', '\\\\').replace('"', '\\"')
|
|
|
|
result += ' {\n'
|
|
result += f' "id": "{q["id"]}",\n'
|
|
result += f' "question": "{question_str}",\n'
|
|
result += f' "answer": "{answer_str}"\n'
|
|
result += ' }'
|
|
|
|
if i < len(all_sub_questions) - 1:
|
|
result += ','
|
|
result += '\n'
|
|
|
|
result += ' ]\n'
|
|
result += ' }\n ]'
|
|
|
|
return result
|
|
|
|
# 处理所有的questions数组
|
|
pattern = r'"questions":\s*\[(.*?)\]\s*(?=\})'
|
|
new_content = re.sub(pattern, merge_questions, content, flags=re.DOTALL)
|
|
|
|
# 保存处理后的文件
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|
f.write(new_content)
|
|
|
|
print("✅ 面试题结构修改完成!")
|
|
print("- 所有题目已合并到同一张卡片")
|
|
print("- 答案换行已转换为<br/>标签")
|
|
print("- 选择题答案已处理为只显示正确答案")
|
|
|
|
# 验证语法
|
|
import subprocess
|
|
result = subprocess.run(['node', '-c', 'src/mocks/resumeInterviewMock.js'],
|
|
capture_output=True, text=True)
|
|
if result.returncode == 0:
|
|
print("✅ 语法检查通过!")
|
|
else:
|
|
print("❌ 语法错误:")
|
|
print(result.stderr) |