100 lines
3.7 KiB
Python
100 lines
3.7 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
print("正在修复文件结构...")
|
|||
|
|
|
|||
|
|
# 读取文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 备份原始文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js.backup_structure', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print("✅ 已创建备份文件: src/mocks/resumeInterviewMock.js.backup_structure")
|
|||
|
|
|
|||
|
|
# 查找所有在 }] 后面出现的孤立的 compound_skills 或其他内容
|
|||
|
|
# 这些是破坏结构的多余内容
|
|||
|
|
issues_found = 0
|
|||
|
|
|
|||
|
|
# 第一步:查找并删除所有多余的compound_skills等内容
|
|||
|
|
# 在每个行业数组结束后,如果有多余的内容,删除它们
|
|||
|
|
pattern = r'(\}\s*\}\s*\],)\s*compound_skills:\s*\[[^\]]*?\],\s*personal_summary:\s*"[^"]*?"\s*\}\s*\}\s*\],\s*("[\w\u4e00-\u9fff]+": \[)'
|
|||
|
|
|
|||
|
|
matches = re.findall(pattern, content)
|
|||
|
|
if matches:
|
|||
|
|
print(f"发现 {len(matches)} 处多余的compound_skills结构")
|
|||
|
|
content = re.sub(pattern, r'\1\n \2', content)
|
|||
|
|
issues_found += len(matches)
|
|||
|
|
|
|||
|
|
# 第二步:查找并删除孤立的数组元素
|
|||
|
|
# 在 ], 后面直接跟着字符串的情况
|
|||
|
|
pattern2 = r'(\],)\s*("[^"]+",[\s\S]*?)\],\s*personal_summary:'
|
|||
|
|
matches2 = re.findall(pattern2, content)
|
|||
|
|
if matches2:
|
|||
|
|
print(f"发现 {len(matches2)} 处孤立的数组元素")
|
|||
|
|
# 只保留第一个 ],
|
|||
|
|
content = re.sub(pattern2, r'\1', content)
|
|||
|
|
issues_found += len(matches2)
|
|||
|
|
|
|||
|
|
# 第三步:确保resumeTemplates正确结束
|
|||
|
|
# 检查第6516行附近的结构
|
|||
|
|
lines = content.split('\n')
|
|||
|
|
for i in range(len(lines)):
|
|||
|
|
if i > 6510 and i < 6520:
|
|||
|
|
# 在resumeTemplates结束的地方,确保有正确的分号
|
|||
|
|
if lines[i].strip() == '};' and i == 6515:
|
|||
|
|
# 这是正确的
|
|||
|
|
pass
|
|||
|
|
elif lines[i].strip() == '}' and i == 6515:
|
|||
|
|
lines[i] = ' };'
|
|||
|
|
print(f"修复了第 {i+1} 行:添加了分号")
|
|||
|
|
issues_found += 1
|
|||
|
|
|
|||
|
|
content = '\n'.join(lines)
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
print(f"\n✅ 修复完成,共修复了 {issues_found} 处问题")
|
|||
|
|
|
|||
|
|
# 验证文件语法
|
|||
|
|
import subprocess
|
|||
|
|
result = subprocess.run(['node', '-c', 'src/mocks/resumeInterviewMock.js'],
|
|||
|
|
capture_output=True, text=True)
|
|||
|
|
if result.returncode == 0:
|
|||
|
|
print("✅ 文件语法验证通过!")
|
|||
|
|
|
|||
|
|
# 测试数据加载
|
|||
|
|
test_code = """
|
|||
|
|
const { resumeInterviewMockData } = require('./src/mocks/resumeInterviewMock.js');
|
|||
|
|
console.log('Industries数量:', resumeInterviewMockData.industries.length);
|
|||
|
|
console.log('ResumeTemplates键数量:', Object.keys(resumeInterviewMockData.resumeTemplates).length);
|
|||
|
|
const camping = resumeInterviewMockData.resumeTemplates['露营地运营'];
|
|||
|
|
console.log('露营地运营模板数量:', camping ? camping.length : 0);
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
with open('test_load.js', 'w') as f:
|
|||
|
|
f.write(test_code)
|
|||
|
|
|
|||
|
|
result2 = subprocess.run(['node', 'test_load.js'], capture_output=True, text=True)
|
|||
|
|
if result2.returncode == 0:
|
|||
|
|
print("\n数据加载测试:")
|
|||
|
|
print(result2.stdout)
|
|||
|
|
else:
|
|||
|
|
print(f"\n数据加载失败: {result2.stderr}")
|
|||
|
|
else:
|
|||
|
|
print(f"❌ 文件仍有语法错误:\n{result.stderr}")
|
|||
|
|
print("\n尝试定位错误位置...")
|
|||
|
|
# 提取错误行号
|
|||
|
|
import re
|
|||
|
|
match = re.search(r':(\d+)', result.stderr)
|
|||
|
|
if match:
|
|||
|
|
line_num = int(match.group(1))
|
|||
|
|
print(f"错误在第 {line_num} 行附近:")
|
|||
|
|
for i in range(max(0, line_num-3), min(len(lines), line_num+3)):
|
|||
|
|
prefix = ">>> " if i == line_num-1 else " "
|
|||
|
|
print(f"{prefix}{i+1}: {lines[i][:100]}")
|