50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
# 读取文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 查找有问题的结构:在 ], 后面直接跟着 compound_skills: [
|
|||
|
|
# 这种结构破坏了JSON格式,需要删除
|
|||
|
|
pattern = r'(\s*\]\s*,)\s*compound_skills:\s*\[[^\]]*?\],\s*personal_summary:\s*"[^"]*?"\s*\}\s*\}\s*\],\s*("(?:新媒体运营|文旅产品设计|品牌运营|旅游)":\s*\[)'
|
|||
|
|
|
|||
|
|
def fix_structure(match):
|
|||
|
|
# 保留第一个 ], 和后面正确的行业开始
|
|||
|
|
return match.group(1) + '\n ' + match.group(2)
|
|||
|
|
|
|||
|
|
# 使用更精确的模式
|
|||
|
|
# 匹配露营地运营后面的多余部分
|
|||
|
|
pattern1 = r'( \}\s*\}\s*\],)\s*compound_skills:\s*\[[^\]]*?\],\s*personal_summary:\s*"[^"]*?"\s*\}\s*\}\s*\],\s*("新媒体运营":\s*\[)'
|
|||
|
|
|
|||
|
|
content = re.sub(pattern1, r'\1\n \2', content)
|
|||
|
|
|
|||
|
|
# 查找并修复其他类似的问题
|
|||
|
|
# 匹配任何在 }] 后面跟着 compound_skills 的情况
|
|||
|
|
pattern2 = r'(\}\s*\]\s*,)\s*compound_skills:\s*\[[^\[]*?\],\s*(?="[^"]+":)'
|
|||
|
|
|
|||
|
|
count = 0
|
|||
|
|
while True:
|
|||
|
|
new_content = re.sub(pattern2, r'\1\n ', content)
|
|||
|
|
if new_content == content:
|
|||
|
|
break
|
|||
|
|
content = new_content
|
|||
|
|
count += 1
|
|||
|
|
print(f"修复了第 {count} 处问题")
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
print(f"✅ 修复完成,共修复了 {count} 处结构问题")
|
|||
|
|
|
|||
|
|
# 验证文件语法
|
|||
|
|
import subprocess
|
|||
|
|
result = subprocess.run(['node', '-c', 'src/mocks/resumeInterviewMock.js'],
|
|||
|
|
capture_output=True, text=True)
|
|||
|
|
if result.returncode == 0:
|
|||
|
|
print("✅ 文件语法验证通过")
|
|||
|
|
else:
|
|||
|
|
print(f"❌ 文件仍有语法错误:\n{result.stderr}")
|