#!/usr/bin/env python3 # -*- coding: utf-8 -*- import re print("安全清理重复的questions数组...") # 读取文件 with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f: content = f.read() # 备份 with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js.backup_clean_safe', 'w', encoding='utf-8') as f: f.write(content) # 对每个岗位群,找到并删除第二个questions数组 industries = ['health_1', 'health_2', 'health_3', 'health_4', 'health_5', 'health_6', 'health_7', 'health_8', 'health_9', 'health_10', 'health_11'] for industry_id in industries: print(f"处理 {industry_id}...") # 找到该岗位群 pattern = rf'"id":\s*"{industry_id}"' match = re.search(pattern, content) if not match: continue start = match.start() # 找到下一个岗位群或数组结束 next_pattern = rf'"id":\s*"health_\d+"' next_matches = list(re.finditer(next_pattern, content[start + 10:])) if next_matches: end = start + 10 + next_matches[0].start() else: # 最后一个岗位群 end_match = re.search(r'\n\];', content[start:]) if end_match: end = start + end_match.start() else: end = len(content) # 获取该岗位群的内容 industry_content = content[start:end] # 查找所有questions数组的开始位置 questions_matches = list(re.finditer(r'"questions":\s*\[', industry_content)) if len(questions_matches) > 1: print(f" 发现 {len(questions_matches)} 个questions数组") # 找到第二个questions的开始和结束 second_start = questions_matches[1].start() # 计算括号平衡找到第二个questions的结束 bracket_count = 0 in_array = False second_end = -1 for i in range(second_start, len(industry_content)): if industry_content[i] == '[': if not in_array and '"questions"' in industry_content[max(0, i-20):i]: in_array = True bracket_count = 1 elif in_array: bracket_count += 1 elif industry_content[i] == ']' and in_array: bracket_count -= 1 if bracket_count == 0: second_end = i + 1 break if second_end > 0: # 找到第二个questions前的逗号 comma_before = industry_content.rfind(',', 0, second_start) # 删除从逗号到questions结束的内容 if comma_before > 0: new_industry_content = industry_content[:comma_before] + industry_content[second_end:] # 替换原内容 content = content[:start] + new_industry_content + content[end:] print(f" ✓ 删除了 {industry_id} 的第二个questions数组") # 写回文件 with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f: f.write(content) print("✓ 清理完成!")