Files
ALL-teach_sys/frontend_大健康/update_modified_resumes.py

182 lines
6.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import os
import re
def load_modified_resumes():
"""加载大健康修改版简历"""
modified_folder = '网页未导入数据/大健康产业/大健康修改版简历'
modified_resumes = {}
for filename in os.listdir(modified_folder):
if filename.endswith('.md'):
position_name = filename.replace('.md', '')
filepath = os.path.join(modified_folder, filename)
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
modified_resumes[position_name] = content
return modified_resumes
def get_modified_positions():
"""获取有修改版的岗位列表"""
modified_resumes = load_modified_resumes()
return list(modified_resumes.keys())
def update_resumeinterview_mock():
"""更新resumeInterviewMock.js中的modified字段"""
# 加载修改版简历
modified_resumes = load_modified_resumes()
print(f"找到 {len(modified_resumes)} 个修改版简历:")
for position in modified_resumes.keys():
print(f" - {position}")
# 读取当前的mock文件
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
content = f.read()
# 解析出resumeTemplates部分
templates_match = re.search(r'const resumeTemplates = (\{[\s\S]*?\});', content)
if not templates_match:
print("错误无法找到resumeTemplates")
return False
templates_json_str = templates_match.group(1)
# 解析JSON
try:
templates_data = json.loads(templates_json_str)
except json.JSONDecodeError as e:
print(f"JSON解析错误: {e}")
return False
# 更新modified字段
updated_count = 0
for group_name, templates in templates_data.items():
for template in templates:
position_name = template['position']
# 检查是否有对应的修改版简历
matching_key = None
for key in modified_resumes.keys():
# 处理可能的名称差异(如"营养师助理" vs "营养师"
if key == position_name or key.replace('助理', '') == position_name or position_name.startswith(key):
matching_key = key
break
if matching_key:
# 更新modified字段
template['content']['modified'] = modified_resumes[matching_key]
updated_count += 1
print(f"✅ 更新: {position_name} <- {matching_key}")
print(f"\n共更新了 {updated_count} 个岗位的修改版简历")
# 重新构建完整的文件内容
new_templates_str = json.dumps(templates_data, ensure_ascii=False, indent=2)
new_content = re.sub(
r'const resumeTemplates = \{[\s\S]*?\};',
f'const resumeTemplates = {new_templates_str};',
content,
count=1
)
# 备份原文件
import shutil
from datetime import datetime
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
backup_file = f'src/mocks/resumeInterviewMock.js.backup_modified_{timestamp}'
shutil.copy('src/mocks/resumeInterviewMock.js', backup_file)
print(f"\n已备份原文件到: {backup_file}")
# 写回文件
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
f.write(new_content)
print("✅ 成功更新 resumeInterviewMock.js")
return True
def update_has_modified_version_list():
"""更新hasRealModifiedVersion函数中的岗位列表"""
# 获取有修改版的岗位列表
modified_positions = get_modified_positions()
# 读取ResumeInterviewPage组件
page_file = 'src/pages/ResumeInterviewPage/index.jsx'
with open(page_file, 'r', encoding='utf-8') as f:
content = f.read()
# 查找hasRealModifiedVersion函数
pattern = r'const hasRealModifiedVersion = \(positionTitle\) => \{[\s\S]*?const modifiedPositions = \[([\s\S]*?)\];'
match = re.search(pattern, content)
if match:
# 构建新的岗位列表
new_positions_list = ',\n '.join([f'"{pos}"' for pos in modified_positions])
new_positions_array = f'[\n {new_positions_list}\n ]'
# 替换旧的岗位列表
new_function = f'''const hasRealModifiedVersion = (positionTitle) => {{
const modifiedPositions = {new_positions_array};'''
new_content = re.sub(
r'const hasRealModifiedVersion = \(positionTitle\) => \{[\s\S]*?const modifiedPositions = \[[^\]]*?\]',
new_function,
content,
count=1
)
# 备份并更新文件
import shutil
from datetime import datetime
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
backup_file = f'{page_file}.backup_{timestamp}'
shutil.copy(page_file, backup_file)
with open(page_file, 'w', encoding='utf-8') as f:
f.write(new_content)
print(f"\n✅ 更新了 ResumeInterviewPage 中的 hasRealModifiedVersion 函数")
print(f"包含 {len(modified_positions)} 个有修改版的岗位")
else:
print("警告无法找到hasRealModifiedVersion函数")
def verify_syntax():
"""验证文件语法"""
import subprocess
result = subprocess.run(
['node', '-c', 'src/mocks/resumeInterviewMock.js'],
capture_output=True,
text=True
)
if result.returncode == 0:
print("\n✅ resumeInterviewMock.js 语法检查通过")
return True
else:
print(f"\n❌ 语法错误:{result.stderr[:200]}")
return False
def main():
print("开始更新修改版简历数据...\n")
# 更新resumeInterviewMock.js中的modified字段
if update_resumeinterview_mock():
# 更新ResumeInterviewPage中的岗位列表
update_has_modified_version_list()
# 验证语法
verify_syntax()
print("\n🎉 修改版简历数据更新完成!")
else:
print("\n❌ 更新失败")
if __name__ == "__main__":
main()