- 包含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>
188 lines
6.8 KiB
Python
188 lines
6.8 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
|
||
import json
|
||
import re
|
||
|
||
print("合并面试题到单个卡片并删除序号...")
|
||
|
||
# 备份当前文件
|
||
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
||
content = f.read()
|
||
|
||
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js.backup_before_final_merge', 'w', encoding='utf-8') as f:
|
||
f.write(content)
|
||
|
||
# 提取industries数组的内容
|
||
industries_pattern = r'const industries = (\[.*?\]);'
|
||
industries_match = re.search(industries_pattern, content, re.DOTALL)
|
||
|
||
if not industries_match:
|
||
print("❌ 无法找到industries数据")
|
||
exit(1)
|
||
|
||
# 将JavaScript转换为JSON格式
|
||
industries_js = industries_match.group(1)
|
||
# 处理JavaScript对象到JSON的转换
|
||
industries_js = re.sub(r'(\w+):', r'"\1":', industries_js) # 添加引号到键
|
||
industries_js = re.sub(r':\s*"([^"]*)"', lambda m: ': "' + m.group(1).replace('\n', '\\n') + '"', industries_js)
|
||
|
||
# 解析为Python对象
|
||
mock_data = None
|
||
try:
|
||
industries = json.loads(industries_js)
|
||
except json.JSONDecodeError as e:
|
||
# 如果JSON解析失败,尝试使用eval(注意:实际生产环境应避免使用eval)
|
||
print(f"JSON解析失败: {e}")
|
||
print("尝试使用备用方法...")
|
||
|
||
# 从文件中直接提取数据结构
|
||
exec_globals = {}
|
||
exec_locals = {}
|
||
|
||
# 创建一个临时的JavaScript到Python转换
|
||
temp_content = content.replace('const industries = ', 'industries = ')
|
||
temp_content = temp_content.replace('const resumeTemplates = ', 'resumeTemplates = ')
|
||
temp_content = temp_content.replace('export ', '# export ')
|
||
|
||
# 提取industries部分
|
||
start_idx = temp_content.find('industries = [')
|
||
end_idx = temp_content.find('];', start_idx) + 2
|
||
industries_str = temp_content[start_idx:end_idx]
|
||
|
||
# 尝试通过更安全的方式解析
|
||
# 先读取备份文件看看正确的格式
|
||
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/health_mock_data.json', 'r', encoding='utf-8') as f:
|
||
mock_data = json.load(f)
|
||
industries = mock_data['industries']
|
||
|
||
print(f"找到 {len(industries)} 个岗位群")
|
||
|
||
# 处理每个岗位群的面试题
|
||
for industry in industries:
|
||
if 'questions' in industry and isinstance(industry['questions'], list) and len(industry['questions']) > 1:
|
||
print(f"处理 {industry['name']} 的面试题...")
|
||
|
||
# 收集所有子问题
|
||
all_sub_questions = []
|
||
question_counter = 1
|
||
|
||
# 遍历所有面试题卡片
|
||
for question_card in industry['questions']:
|
||
if 'subQuestions' in question_card:
|
||
for sub_q in question_card['subQuestions']:
|
||
# 删除问题开头的序号
|
||
question_text = sub_q['question']
|
||
question_text = re.sub(r'^\d+\.\s*', '', question_text)
|
||
|
||
all_sub_questions.append({
|
||
'id': f'q{question_counter}',
|
||
'question': question_text,
|
||
'answer': sub_q['answer']
|
||
})
|
||
question_counter += 1
|
||
|
||
# 创建单个合并的卡片
|
||
merged_card = {
|
||
'id': f"{industry['id']}_q1",
|
||
'question': f"{industry['name']}岗位群面试题",
|
||
'subQuestions': all_sub_questions
|
||
}
|
||
|
||
# 替换为单个卡片
|
||
industry['questions'] = [merged_card]
|
||
print(f"✓ {industry['name']}: 合并为1个卡片,包含 {len(all_sub_questions)} 个问题")
|
||
|
||
elif 'questions' in industry and len(industry['questions']) == 1:
|
||
# 如果已经是单个卡片,只需要删除序号
|
||
if 'subQuestions' in industry['questions'][0]:
|
||
for sub_q in industry['questions'][0]['subQuestions']:
|
||
sub_q['question'] = re.sub(r'^\d+\.\s*', '', sub_q['question'])
|
||
print(f"✓ {industry['name']}: 已是单卡片,删除了序号")
|
||
|
||
# 提取resumeTemplates
|
||
resumeTemplates_pattern = r'const resumeTemplates = (\{.*?\});'
|
||
resumeTemplates_match = re.search(resumeTemplates_pattern, content, re.DOTALL)
|
||
|
||
if resumeTemplates_match:
|
||
resumeTemplates_js = resumeTemplates_match.group(1)
|
||
# 类似处理,这里直接从mock_data获取
|
||
if mock_data:
|
||
resumeTemplates = mock_data['resumeTemplates']
|
||
else:
|
||
# 如果没有mock_data,从health_mock_data.json读取
|
||
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/health_mock_data.json', 'r', encoding='utf-8') as f:
|
||
temp_data = json.load(f)
|
||
resumeTemplates = temp_data['resumeTemplates']
|
||
else:
|
||
resumeTemplates = {}
|
||
|
||
# 转换为JavaScript格式
|
||
industries_js = json.dumps(industries, ensure_ascii=False, indent=2)
|
||
resumeTemplates_js = json.dumps(resumeTemplates, ensure_ascii=False, indent=2)
|
||
|
||
# 创建新的Mock文件内容
|
||
new_content = f"""// 简历与面试题Mock数据
|
||
|
||
// 岗位群列表
|
||
const industries = {industries_js};
|
||
|
||
// 简历模板数据
|
||
const resumeTemplates = {resumeTemplates_js};
|
||
|
||
// 我的简历数据
|
||
const myResume = {{
|
||
personalInfo: {{
|
||
name: "张三",
|
||
phone: "138****8888",
|
||
email: "zhangsan@example.com",
|
||
age: 25,
|
||
education: "苏州信息职业技术学院 2020.9-2023.6",
|
||
experience: "2年",
|
||
location: "北京"
|
||
}},
|
||
workExperience: [
|
||
{{
|
||
company: "某健康管理公司",
|
||
position: "健康管理师",
|
||
duration: "2022.03-2024.01",
|
||
description: "负责健康评估和健康管理方案制定工作"
|
||
}}
|
||
],
|
||
skills: ["健康评估", "健康管理", "数据分析", "客户服务"],
|
||
projects: [
|
||
{{
|
||
name: "企业员工健康管理项目",
|
||
role: "健康管理师",
|
||
duration: "2023.05-2023.12",
|
||
description: "负责企业员工的健康评估和管理方案制定"
|
||
}}
|
||
]
|
||
}};
|
||
|
||
// 获取页面mock数据的函数
|
||
export function getMockPageData() {{
|
||
return resumeInterviewMockData;
|
||
}}
|
||
|
||
// 导出合并的数据
|
||
export const resumeInterviewMockData = {{
|
||
industries,
|
||
resumeTemplates,
|
||
myResume
|
||
}};
|
||
"""
|
||
|
||
# 写入新内容
|
||
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
||
f.write(new_content)
|
||
|
||
# 同时更新JSON文件以保持一致
|
||
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/health_mock_data_full.json', 'w', encoding='utf-8') as f:
|
||
json.dump({'industries': industries, 'resumeTemplates': resumeTemplates}, f, ensure_ascii=False, indent=2)
|
||
|
||
print("\n✓ 面试题合并完成!")
|
||
print(" - 每个岗位群只有一个面试题卡片")
|
||
print(" - 删除了所有题目前的序号")
|
||
print(" - 原文件已备份为 resumeInterviewMock.js.backup_before_final_merge")
|
||
print(" - 同步更新了 health_mock_data_full.json") |