Files
ALL-teach_sys/frontend_视觉设计/update_modified_resumes.py

110 lines
4.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import json
import re
import os
# 定义需要更新的岗位和对应的修改版简历文件
positions_to_update = {
"UI设计师": "UI设计师.md",
"包装设计师": "包装设计师.md",
"插画师": "插画师.md",
"AI绘画师": "AI绘画师.md",
"影视灯光": "影视灯光.md",
"角色原画师": "角色原画师.md",
"CG总监助理": "CG总监助理.md",
"品牌视觉内容策划": "品牌视觉内容策划.md",
"摄影美术指导助理": "摄影美术指导助理.md",
"影视摄像": "影视摄像.md",
"摄影师": "摄影师.md"
}
# 读取简历修改版文件并清理删除线内容
def read_and_clean_resume(filepath):
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# 去除标题行(第一行)
lines = content.split('\n')
if lines[0].startswith('# '):
content = '\n'.join(lines[1:]).strip()
# 清理删除线和加粗标记
# 删除~~xxx~~之间的内容,保留后面的内容
content = re.sub(r'~~[^~]+~~\s*', '', content)
# 去除加粗标记
content = re.sub(r'\*\*(.*?)\*\*', r'\1', content)
return content
# 主程序
print("开始更新modified字段...")
# 读取所有修改版简历
modified_resumes = {}
for position, filename in positions_to_update.items():
filepath = f"网页未导入数据/视觉设计产业/视觉设计修改版简历/{filename}"
if os.path.exists(filepath):
modified_resumes[position] = read_and_clean_resume(filepath)
print(f"✓ 读取 {position} 的修改版简历")
else:
print(f"✗ 未找到 {position} 的修改版简历文件: {filepath}")
# 读取resumeInterviewMock.js文件
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
content = f.read()
# 备份原文件
import datetime
backup_time = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
with open(f'src/mocks/resumeInterviewMock.js.backup_{backup_time}', 'w', encoding='utf-8') as f:
f.write(content)
print(f"已创建备份: resumeInterviewMock.js.backup_{backup_time}")
# 更新每个岗位的modified字段
updated_count = 0
for position, resume_content in modified_resumes.items():
# 查找对应岗位的modified字段位置
# 需要处理字符串转义
escaped_content = json.dumps(resume_content, ensure_ascii=False)[1:-1]
# 查找该岗位对应的简历数据位置
if position == "UI设计师":
pattern = r'("position": "UI设计师",[\s\S]*?"modified": ")[^"]*(")'
elif position == "包装设计师":
pattern = r'("position": "包装设计师",[\s\S]*?"modified": ")[^"]*(")'
# ... 其他岗位类似
# 使用更通用的方法找到position然后找下一个modified字段
# 搜索 "position": "岗位名" 后面最近的 "modified": "..."
position_pattern = f'"position": "{position}"'
if position_pattern in content:
# 找到position的位置
pos = content.find(position_pattern)
if pos != -1:
# 从这个位置开始找下一个modified字段
modified_start = content.find('"modified": "', pos)
if modified_start != -1:
# 找到modified字段的结束位置考虑转义字符
quote_count = 0
i = modified_start + len('"modified": "')
while i < len(content):
if content[i] == '"' and content[i-1] != '\\':
break
i += 1
# 替换modified字段的内容
before = content[:modified_start + len('"modified": "')]
after = content[i:]
content = before + escaped_content + after
updated_count += 1
print(f"✓ 已更新 {position} 的modified字段")
if updated_count > 0:
# 写回文件
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
f.write(content)
print(f"\n成功更新 {updated_count} 个岗位的modified字段")
else:
print("\n未能更新任何岗位,请检查文件格式")