110 lines
3.3 KiB
Python
110 lines
3.3 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import re
|
|||
|
|
import os
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
def create_backup(file_path):
|
|||
|
|
"""创建备份文件"""
|
|||
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|||
|
|
backup_path = f"{file_path}.backup_{timestamp}"
|
|||
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
with open(backup_path, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print(f"已创建备份: {backup_path}")
|
|||
|
|
return backup_path
|
|||
|
|
|
|||
|
|
def clean_markdown_content(content):
|
|||
|
|
"""清理markdown内容"""
|
|||
|
|
# 删除删除线内容(两种格式)
|
|||
|
|
content = re.sub(r'~~[^~]+~~', '', content)
|
|||
|
|
content = re.sub(r'~~[^~]+~~', '', content)
|
|||
|
|
|
|||
|
|
# 移除加粗格式
|
|||
|
|
content = re.sub(r'\*\*([^*]+)\*\*', r'\1', content)
|
|||
|
|
content = re.sub(r'__([^_]+)__', r'\1', content)
|
|||
|
|
|
|||
|
|
# 清理多余的空行
|
|||
|
|
content = re.sub(r'\n{3,}', '\n\n', content)
|
|||
|
|
content = re.sub(r' {2,}', ' ', content)
|
|||
|
|
|
|||
|
|
# 移除行首尾空格
|
|||
|
|
lines = content.split('\n')
|
|||
|
|
lines = [line.strip() for line in lines]
|
|||
|
|
content = '\n'.join(lines)
|
|||
|
|
|
|||
|
|
return content.strip()
|
|||
|
|
|
|||
|
|
def update_modified_resumes():
|
|||
|
|
"""更新10个岗位的修改版简历内容"""
|
|||
|
|
|
|||
|
|
# 岗位列表
|
|||
|
|
positions = [
|
|||
|
|
"会展策划师",
|
|||
|
|
"会展执行助理",
|
|||
|
|
"会展讲解员",
|
|||
|
|
"活动策划师",
|
|||
|
|
"活动执行",
|
|||
|
|
"漫展策划师",
|
|||
|
|
"旅游规划师",
|
|||
|
|
"旅游计调专员",
|
|||
|
|
"景区运营专员",
|
|||
|
|
"文旅运营总监助理"
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
# 修改版简历文件夹路径
|
|||
|
|
resume_folder = "/Users/apple/Documents/cursor/教务系统/frontend/网页未导入数据/文旅产业/修改后简历"
|
|||
|
|
|
|||
|
|
# 目标文件路径
|
|||
|
|
target_file = "src/mocks/resumeInterviewMock.js"
|
|||
|
|
|
|||
|
|
# 创建备份
|
|||
|
|
create_backup(target_file)
|
|||
|
|
|
|||
|
|
# 读取目标文件
|
|||
|
|
with open(target_file, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 处理每个岗位
|
|||
|
|
for position in positions:
|
|||
|
|
# 读取修改版简历内容
|
|||
|
|
resume_file = os.path.join(resume_folder, f"{position}.md")
|
|||
|
|
if not os.path.exists(resume_file):
|
|||
|
|
print(f"⚠️ 文件不存在: {resume_file}")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
with open(resume_file, 'r', encoding='utf-8') as f:
|
|||
|
|
modified_content = f.read()
|
|||
|
|
|
|||
|
|
# 清理内容
|
|||
|
|
modified_content = clean_markdown_content(modified_content)
|
|||
|
|
|
|||
|
|
# 转义反引号
|
|||
|
|
modified_content = modified_content.replace('`', '\\`')
|
|||
|
|
|
|||
|
|
# 查找并更新对应位置
|
|||
|
|
# 使用更精确的正则表达式匹配
|
|||
|
|
pattern = rf'(position:\s*"{re.escape(position)}"[^{{]*content:\s*{{[^}}]*modified:\s*`)([^`]*?)(`)'
|
|||
|
|
|
|||
|
|
def replace_func(match):
|
|||
|
|
return match.group(1) + modified_content + match.group(3)
|
|||
|
|
|
|||
|
|
# 执行替换
|
|||
|
|
new_content, count = re.subn(pattern, replace_func, content, flags=re.DOTALL)
|
|||
|
|
|
|||
|
|
if count > 0:
|
|||
|
|
content = new_content
|
|||
|
|
print(f"✓ 已更新 {position}")
|
|||
|
|
else:
|
|||
|
|
print(f"✗ 未找到 {position} 的modified字段")
|
|||
|
|
|
|||
|
|
# 保存更新后的文件
|
|||
|
|
with open(target_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
print("\n更新完成!")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
update_modified_resumes()
|