- 包含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>
151 lines
6.0 KiB
Python
151 lines
6.0 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
|
||
import json
|
||
import re
|
||
import sys
|
||
|
||
def escape_for_js(text):
|
||
"""转义字符串用于JavaScript"""
|
||
if not text:
|
||
return ""
|
||
text = text.replace('\\', '\\\\')
|
||
text = text.replace('`', '\\`')
|
||
text = text.replace('${', '\\${')
|
||
return text
|
||
|
||
def parse_resume_content(resume_content):
|
||
"""解析简历内容,提取项目经历、专业技能和个人总结"""
|
||
# 项目经历
|
||
project_match = re.search(r'# 一、项目经历(.*?)(?=# 二、|$)', resume_content, re.DOTALL)
|
||
project_experience = ""
|
||
if project_match:
|
||
project_text = project_match.group(1).strip()
|
||
project_text = project_text.replace('### ', '')
|
||
project_text = project_text.replace('# ', '')
|
||
project_experience = project_text
|
||
|
||
# 专业技能
|
||
skills_match = re.search(r'# 二、[专业技能|掌握技能](.*?)(?=# 三、|$)', resume_content, re.DOTALL)
|
||
skills = ""
|
||
if skills_match:
|
||
skills_text = skills_match.group(1).strip()
|
||
skills_text = skills_text.replace('### ', '')
|
||
skills_text = skills_text.replace('# ', '')
|
||
skills = skills_text
|
||
|
||
# 个人总结
|
||
summary_match = re.search(r'# 三、[个人总结|个人评价](.*?)$', resume_content, re.DOTALL)
|
||
summary = ""
|
||
if summary_match:
|
||
summary_text = summary_match.group(1).strip()
|
||
summary = summary_text
|
||
|
||
return {
|
||
'projectExperience': project_experience,
|
||
'skills': skills,
|
||
'personalSummary': summary
|
||
}
|
||
|
||
def process_part(part_number):
|
||
"""处理指定部分的简历数据"""
|
||
# 读取对应部分的JSON文件
|
||
file_path = f'/Users/apple/Documents/cursor/教务系统/frontend/网页未导入数据/个人简历内容_part{part_number}.json'
|
||
print(f"\n处理第 {part_number} 部分...")
|
||
|
||
with open(file_path, 'r', encoding='utf-8') as f:
|
||
data = json.load(f)
|
||
|
||
# 创建岗位名称到简历内容的映射
|
||
position_map = {}
|
||
for item in data:
|
||
if '❌岗位名称查询' in item and '简历内容' in item:
|
||
position_name = item['❌岗位名称查询']
|
||
resume_data = parse_resume_content(item['简历内容'])
|
||
position_map[position_name] = resume_data
|
||
print(f" 处理岗位: {position_name}")
|
||
|
||
# 保存映射数据
|
||
output_file = f'/Users/apple/Documents/cursor/教务系统/frontend/scripts/resume_mapping_part{part_number}.json'
|
||
with open(output_file, 'w', encoding='utf-8') as f:
|
||
json.dump(position_map, f, ensure_ascii=False, indent=2)
|
||
|
||
print(f"第 {part_number} 部分处理完成,共处理 {len(position_map)} 个岗位")
|
||
print(f"映射数据已保存到: {output_file}")
|
||
|
||
return position_map
|
||
|
||
def update_mockdata_with_mapping(position_map, part_number):
|
||
"""使用映射数据更新mockData.js"""
|
||
print(f"\n开始更新 mockData.js (第 {part_number} 部分)...")
|
||
|
||
# 读取当前的mockData.js文件
|
||
with open('/Users/apple/Documents/cursor/教务系统/frontend/src/data/mockData.js', 'r', encoding='utf-8') as f:
|
||
content = f.read()
|
||
|
||
updated_count = 0
|
||
|
||
# 对每个岗位进行更新
|
||
for position_name, resume_data in position_map.items():
|
||
# 查找该岗位在mockData.js中的位置
|
||
# 使用更灵活的模式匹配
|
||
pattern = rf'name:\s*["\']({re.escape(position_name)})["\']'
|
||
matches = list(re.finditer(pattern, content))
|
||
|
||
if matches:
|
||
for match in matches:
|
||
# 找到岗位后,需要在其resume对象中添加新字段
|
||
start_pos = match.start()
|
||
|
||
# 查找该岗位的resume对象
|
||
resume_pattern = r'resume:\s*\{'
|
||
resume_match = re.search(resume_pattern, content[start_pos:start_pos+2000])
|
||
|
||
if resume_match:
|
||
resume_start = start_pos + resume_match.end()
|
||
|
||
# 查找resume对象的结束位置
|
||
brace_count = 1
|
||
i = resume_start
|
||
while i < len(content) and brace_count > 0:
|
||
if content[i] == '{':
|
||
brace_count += 1
|
||
elif content[i] == '}':
|
||
brace_count -= 1
|
||
i += 1
|
||
|
||
# 在resume对象末尾添加新字段(在最后一个}之前)
|
||
insert_pos = i - 1
|
||
|
||
# 检查是否已经有这些字段
|
||
resume_section = content[resume_start:insert_pos]
|
||
if 'projectExperience' not in resume_section:
|
||
# 构建要插入的内容
|
||
new_fields = f''',
|
||
projectExperience: `{escape_for_js(resume_data['projectExperience'])}`,
|
||
skills: `{escape_for_js(resume_data['skills'])}`,
|
||
personalSummary: `{escape_for_js(resume_data['personalSummary'])}`'''
|
||
|
||
# 插入新字段
|
||
content = content[:insert_pos] + new_fields + content[insert_pos:]
|
||
updated_count += 1
|
||
print(f" ✓ 更新岗位: {position_name}")
|
||
|
||
# 写回文件
|
||
with open('/Users/apple/Documents/cursor/教务系统/frontend/src/data/mockData.js', 'w', encoding='utf-8') as f:
|
||
f.write(content)
|
||
|
||
print(f"第 {part_number} 部分更新完成,共更新 {updated_count} 个岗位")
|
||
return updated_count
|
||
|
||
# 主程序
|
||
if __name__ == "__main__":
|
||
if len(sys.argv) > 1:
|
||
# 处理指定部分
|
||
part_num = int(sys.argv[1])
|
||
position_map = process_part(part_num)
|
||
update_mockdata_with_mapping(position_map, part_num)
|
||
else:
|
||
print("请指定要处理的部分 (1, 2, 或 3)")
|
||
print("使用方法: python3 update_all_positions.py <部分编号>")
|
||
print("例如: python3 update_all_positions.py 1") |