82 lines
2.7 KiB
Python
82 lines
2.7 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
print("最终修复Mock文件结构...")
|
|||
|
|
|
|||
|
|
# 读取文件
|
|||
|
|
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
lines = f.readlines()
|
|||
|
|
|
|||
|
|
# 备份
|
|||
|
|
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js.backup_final_fix', 'w', encoding='utf-8') as f:
|
|||
|
|
f.writelines(lines)
|
|||
|
|
|
|||
|
|
# 找到health_10的questions(在第1787行)
|
|||
|
|
# 需要把从1787行开始的questions移到health_10的positions数组后面
|
|||
|
|
|
|||
|
|
# 找到health_10的positions数组结束(第2073行)
|
|||
|
|
# 在这之前插入questions
|
|||
|
|
|
|||
|
|
# 提取questions内容(从第1787行到某个结束位置)
|
|||
|
|
questions_start = 1786 # 第1787行,索引是1786
|
|||
|
|
questions_lines = []
|
|||
|
|
bracket_count = 0
|
|||
|
|
in_questions = False
|
|||
|
|
|
|||
|
|
for i in range(questions_start, len(lines)):
|
|||
|
|
line = lines[i]
|
|||
|
|
|
|||
|
|
if '"questions": [' in line:
|
|||
|
|
in_questions = True
|
|||
|
|
bracket_count = 1
|
|||
|
|
questions_lines.append(line)
|
|||
|
|
elif in_questions:
|
|||
|
|
questions_lines.append(line)
|
|||
|
|
|
|||
|
|
# 计算括号
|
|||
|
|
bracket_count += line.count('[') - line.count(']')
|
|||
|
|
|
|||
|
|
if bracket_count == 0:
|
|||
|
|
# questions数组结束
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 删除原位置的questions
|
|||
|
|
# 从1785行(有个多余的])开始删除到questions结束
|
|||
|
|
del_start = 1784 # 第1785行
|
|||
|
|
del_end = questions_start + len(questions_lines) + 1
|
|||
|
|
|
|||
|
|
# 删除这些行
|
|||
|
|
new_lines = lines[:del_start] + lines[del_end:]
|
|||
|
|
|
|||
|
|
# 现在需要在health_10的positions数组后插入questions
|
|||
|
|
# 找到正确的位置(positions数组的结束)
|
|||
|
|
# 由于删除了一些行,需要重新定位
|
|||
|
|
|
|||
|
|
# 查找health_10的positions结束位置
|
|||
|
|
for i in range(1760, len(new_lines)):
|
|||
|
|
if 'health_10_4' in new_lines[i]:
|
|||
|
|
# 找到最后一个position
|
|||
|
|
# 继续找到它的结束
|
|||
|
|
for j in range(i, min(i+50, len(new_lines))):
|
|||
|
|
if '}' in new_lines[j] and 'requirements' in ''.join(new_lines[max(0, j-10):j]):
|
|||
|
|
# 这是position对象的结束
|
|||
|
|
# 在下一行插入
|
|||
|
|
insert_pos = j + 1
|
|||
|
|
|
|||
|
|
# 修正格式:确保positions数组正确关闭
|
|||
|
|
new_lines[insert_pos-1] = ' }\n'
|
|||
|
|
|
|||
|
|
# 插入positions数组的关闭和questions
|
|||
|
|
insert_lines = [' ],\n']
|
|||
|
|
insert_lines.extend(questions_lines)
|
|||
|
|
|
|||
|
|
# 在insert_pos插入
|
|||
|
|
new_lines = new_lines[:insert_pos] + insert_lines + new_lines[insert_pos:]
|
|||
|
|
break
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.writelines(new_lines)
|
|||
|
|
|
|||
|
|
print("✓ 修复完成!")
|