122 lines
4.5 KiB
Python
122 lines
4.5 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""
|
||
|
|
修复岗位对象中的原始版简历内容
|
||
|
|
将resumeTemplates中的真实原始版内容复制到industries.positions的content.original中
|
||
|
|
"""
|
||
|
|
|
||
|
|
import json
|
||
|
|
import re
|
||
|
|
import shutil
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
def fix_original_resume_content():
|
||
|
|
"""修复原始版简历内容"""
|
||
|
|
|
||
|
|
file_path = "src/mocks/resumeInterviewMock.js"
|
||
|
|
|
||
|
|
# 创建备份
|
||
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||
|
|
backup_path = f"{file_path}.backup_fix_original_{timestamp}"
|
||
|
|
shutil.copy2(file_path, backup_path)
|
||
|
|
print(f"📦 已创建备份: {backup_path}")
|
||
|
|
|
||
|
|
try:
|
||
|
|
# 读取文件
|
||
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
||
|
|
content = f.read()
|
||
|
|
|
||
|
|
print("🚀 开始修复原始版简历内容...")
|
||
|
|
|
||
|
|
# 需要修复的岗位列表
|
||
|
|
positions_to_fix = [
|
||
|
|
"UI设计师",
|
||
|
|
"包装设计师",
|
||
|
|
"摄影师",
|
||
|
|
"角色原画师",
|
||
|
|
"影视灯光",
|
||
|
|
"摄影美术指导助理",
|
||
|
|
"品牌视觉内容策划",
|
||
|
|
"影视摄像",
|
||
|
|
"AI绘画师",
|
||
|
|
"CG总监助理"
|
||
|
|
]
|
||
|
|
|
||
|
|
# 从resumeTemplates中提取原始版内容的映射
|
||
|
|
resume_templates_pattern = r'const resumeTemplates = \{(.*?)\};'
|
||
|
|
templates_match = re.search(resume_templates_pattern, content, re.DOTALL)
|
||
|
|
|
||
|
|
if not templates_match:
|
||
|
|
print("❌ 无法找到resumeTemplates部分")
|
||
|
|
return
|
||
|
|
|
||
|
|
templates_content = templates_match.group(1)
|
||
|
|
|
||
|
|
# 提取各岗位的原始版内容
|
||
|
|
original_content_map = {}
|
||
|
|
|
||
|
|
for position in positions_to_fix:
|
||
|
|
# 查找该岗位在resumeTemplates中的定义
|
||
|
|
position_pattern = rf'"position":\s*"{re.escape(position)}".*?"original":\s*"([^"]*(?:\\.[^"]*)*)"'
|
||
|
|
position_match = re.search(position_pattern, templates_content, re.DOTALL)
|
||
|
|
|
||
|
|
if position_match:
|
||
|
|
original_content = position_match.group(1)
|
||
|
|
original_content_map[position] = original_content
|
||
|
|
print(f"✅ 找到 {position} 的原始版内容")
|
||
|
|
else:
|
||
|
|
print(f"⚠️ 未找到 {position} 在resumeTemplates中的原始版内容")
|
||
|
|
|
||
|
|
print(f"📊 找到 {len(original_content_map)} 个岗位的原始版内容")
|
||
|
|
|
||
|
|
# 更新industries.positions中的content.original
|
||
|
|
updated_count = 0
|
||
|
|
|
||
|
|
for position_title, original_content in original_content_map.items():
|
||
|
|
# 查找该岗位在industries中的位置
|
||
|
|
position_pattern = rf'("title":\s*"{re.escape(position_title)}".*?"content":\s*\{{.*?"original":\s*")([^"]*(?:\\.[^"]*)*)"'
|
||
|
|
|
||
|
|
def replace_original(match):
|
||
|
|
nonlocal updated_count
|
||
|
|
prefix = match.group(1)
|
||
|
|
old_content = match.group(2)
|
||
|
|
updated_count += 1
|
||
|
|
print(f"🔄 更新 {position_title} 的原始版内容")
|
||
|
|
return prefix + original_content + '"'
|
||
|
|
|
||
|
|
content = re.sub(position_pattern, replace_original, content, flags=re.DOTALL)
|
||
|
|
|
||
|
|
# 写入文件
|
||
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
||
|
|
f.write(content)
|
||
|
|
|
||
|
|
print(f"📊 处理统计:")
|
||
|
|
print(f" - 需要修复的岗位数: {len(positions_to_fix)}")
|
||
|
|
print(f" - 找到原始内容的岗位数: {len(original_content_map)}")
|
||
|
|
print(f" - 成功更新的岗位数: {updated_count}")
|
||
|
|
print(f"✅ 已更新 {file_path}")
|
||
|
|
|
||
|
|
# 验证JS语法
|
||
|
|
import subprocess
|
||
|
|
try:
|
||
|
|
result = subprocess.run(['node', '-c', file_path], capture_output=True, text=True)
|
||
|
|
if result.returncode == 0:
|
||
|
|
print("✅ JavaScript语法验证通过")
|
||
|
|
else:
|
||
|
|
print(f"❌ JavaScript语法验证失败: {result.stderr}")
|
||
|
|
# 恢复备份
|
||
|
|
shutil.copy2(backup_path, file_path)
|
||
|
|
print("🔄 已恢复原始文件")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"⚠️ 无法验证JavaScript语法: {e}")
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
print(f"❌ 处理失败: {e}")
|
||
|
|
# 恢复备份
|
||
|
|
shutil.copy2(backup_path, file_path)
|
||
|
|
print("🔄 已恢复原始文件")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
print("🚀 开始修复原始版简历内容...")
|
||
|
|
fix_original_resume_content()
|
||
|
|
print("🎉 处理完成!")
|