108 lines
3.6 KiB
Python
108 lines
3.6 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import os
|
|||
|
|
import re
|
|||
|
|
import json
|
|||
|
|
|
|||
|
|
def safe_escape_js_string(text):
|
|||
|
|
"""安全地转义JavaScript字符串"""
|
|||
|
|
# 转义反斜杠(必须首先执行)
|
|||
|
|
text = text.replace('\\', '\\\\')
|
|||
|
|
# 转义双引号
|
|||
|
|
text = text.replace('"', '\\"')
|
|||
|
|
# 转义换行符
|
|||
|
|
text = text.replace('\n', '\\n')
|
|||
|
|
# 转义回车符
|
|||
|
|
text = text.replace('\r', '\\r')
|
|||
|
|
# 转义制表符
|
|||
|
|
text = text.replace('\t', '\\t')
|
|||
|
|
return text
|
|||
|
|
|
|||
|
|
def main():
|
|||
|
|
# 修改版简历对应关系
|
|||
|
|
modified_resumes = {
|
|||
|
|
"BIM工程师": "BIM工程师.md",
|
|||
|
|
"工程造价师": "工程造价师.md",
|
|||
|
|
"房产经纪人": "房产经纪人.md",
|
|||
|
|
"监理工程师": "监理工程师.md",
|
|||
|
|
"采购工程师": "采购工程师.md",
|
|||
|
|
"建筑检测工程师": "建筑检测工程师.md",
|
|||
|
|
"施工管理工程师": "施工管理工程师.md",
|
|||
|
|
"设备安装工程师": "设备安装工程师.md",
|
|||
|
|
"建筑给排水设计师": "建筑给排水设计师.md",
|
|||
|
|
"房地产投资分析师": "房地产投资分析师.md"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 读取当前的resumeInterviewMock.js文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
js_content = f.read()
|
|||
|
|
|
|||
|
|
# 依次更新每个岗位的modified字段
|
|||
|
|
for position, filename in modified_resumes.items():
|
|||
|
|
file_path = f'网页未导入数据/土木水利产业/土木水利修改版简历/{filename}'
|
|||
|
|
|
|||
|
|
if not os.path.exists(file_path):
|
|||
|
|
print(f"文件不存在: {file_path}")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 读取修改版简历内容
|
|||
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|||
|
|
resume_content = f.read()
|
|||
|
|
|
|||
|
|
# 安全转义内容
|
|||
|
|
escaped_content = safe_escape_js_string(resume_content)
|
|||
|
|
|
|||
|
|
# 查找该岗位的位置和modified字段
|
|||
|
|
position_pattern = rf'"position": "{re.escape(position)}"'
|
|||
|
|
position_match = re.search(position_pattern, js_content)
|
|||
|
|
|
|||
|
|
if not position_match:
|
|||
|
|
print(f"未找到岗位: {position}")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 从岗位位置开始,查找其modified字段
|
|||
|
|
start_pos = position_match.start()
|
|||
|
|
modified_pattern = r'"modified": "([^"\\]*(\\.[^"\\]*)*)"'
|
|||
|
|
|
|||
|
|
# 在岗位位置之后查找modified字段
|
|||
|
|
search_area = js_content[start_pos:start_pos + 10000] # 限制搜索范围
|
|||
|
|
modified_match = re.search(modified_pattern, search_area)
|
|||
|
|
|
|||
|
|
if not modified_match:
|
|||
|
|
print(f"未找到 {position} 的modified字段")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 计算在完整文件中的位置
|
|||
|
|
modified_start = start_pos + modified_match.start()
|
|||
|
|
modified_end = start_pos + modified_match.end()
|
|||
|
|
|
|||
|
|
# 构建新的modified字段
|
|||
|
|
new_modified = f'"modified": "{escaped_content}"'
|
|||
|
|
|
|||
|
|
# 替换内容
|
|||
|
|
js_content = js_content[:modified_start] + new_modified + js_content[modified_end:]
|
|||
|
|
|
|||
|
|
print(f"✅ 已更新 {position} 的modified字段")
|
|||
|
|
|
|||
|
|
# 保存更新后的文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(js_content)
|
|||
|
|
|
|||
|
|
print("所有modified字段更新完成")
|
|||
|
|
|
|||
|
|
# 验证语法
|
|||
|
|
import subprocess
|
|||
|
|
try:
|
|||
|
|
result = subprocess.run(['node', '-c', 'src/mocks/resumeInterviewMock.js'],
|
|||
|
|
capture_output=True, text=True)
|
|||
|
|
if result.returncode == 0:
|
|||
|
|
print("✅ JavaScript语法检查通过")
|
|||
|
|
else:
|
|||
|
|
print("❌ JavaScript语法错误:")
|
|||
|
|
print(result.stderr)
|
|||
|
|
except Exception as e:
|
|||
|
|
print("无法验证JavaScript语法:", e)
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
main()
|