78 lines
2.6 KiB
Python
78 lines
2.6 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
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():
|
|||
|
|
# 读取BIM工程师的修改版简历
|
|||
|
|
with open('网页未导入数据/土木水利产业/土木水利修改版简历/BIM工程师.md', 'r', encoding='utf-8') as f:
|
|||
|
|
bim_content = f.read()
|
|||
|
|
|
|||
|
|
print("原始内容长度:", len(bim_content))
|
|||
|
|
|
|||
|
|
# 安全转义内容
|
|||
|
|
escaped_content = safe_escape_js_string(bim_content)
|
|||
|
|
print("转义后内容长度:", len(escaped_content))
|
|||
|
|
print("转义后内容前100字符:", escaped_content[:100])
|
|||
|
|
|
|||
|
|
# 读取当前的resumeInterviewMock.js文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
js_content = f.read()
|
|||
|
|
|
|||
|
|
# 查找BIM工程师的modified字段并替换
|
|||
|
|
# 使用更精确的正则表达式来匹配
|
|||
|
|
pattern = r'("modified":\s*"# 对应岗位:BIM工程师[^"]*")'
|
|||
|
|
|
|||
|
|
# 构建新的替换内容
|
|||
|
|
replacement = f'"modified": "{escaped_content}"'
|
|||
|
|
|
|||
|
|
# 查找当前错误的内容位置
|
|||
|
|
error_pattern = r'"modified":\s*"# 对应岗位:BIM工程师[^}]*?(?=")'
|
|||
|
|
|
|||
|
|
# 先查看是否能找到错误位置
|
|||
|
|
match = re.search(error_pattern, js_content, re.DOTALL)
|
|||
|
|
if match:
|
|||
|
|
print("找到错误的modified字段,位置:", match.start(), "-", match.end())
|
|||
|
|
print("错误内容开头:", match.group()[:100])
|
|||
|
|
|
|||
|
|
# 替换内容
|
|||
|
|
new_js_content = re.sub(error_pattern, replacement, js_content, flags=re.DOTALL)
|
|||
|
|
|
|||
|
|
# 保存修复后的文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(new_js_content)
|
|||
|
|
|
|||
|
|
print("已成功修复BIM工程师的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)
|
|||
|
|
else:
|
|||
|
|
print("未找到BIM工程师的modified字段")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
main()
|