#!/usr/bin/env python3 import json import re # 读取文件 with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f: content = f.read() # 找到民宿经营的interviews数据 start_pattern = r'"民宿经营": \[' end_pattern = r'\]\s*,\s*"文创品牌运营"' match = re.search(f'{start_pattern}(.*?){end_pattern}', content, re.DOTALL) if not match: print("未找到民宿经营数据") exit(1) minsu_data = match.group(1) # 提取每个岗位的数据 positions = [] pattern = r'\{\s*position:\s*"([^"]+)".*?studentInfo:\s*(\{[^}]*(?:\{[^}]*\}[^}]*)*\})' matches = re.finditer(pattern, minsu_data, re.DOTALL) for match in matches: position_name = match.group(1) student_info = match.group(2) # 只提取前3个岗位作为示例 if len(positions) < 3: positions.append({ 'position': position_name, 'studentInfo': student_info }) # 生成resumeTemplates格式的代码 output = ' "民宿经营": [\n' for i, pos in enumerate(positions): output += f' {{\n' output += f' position: "{pos["position"]}",\n' output += f' level: "普通岗",\n' output += f' studentInfo: {pos["studentInfo"]}\n' output += f' }}' if i < len(positions) - 1: output += ',' output += '\n' output += ' ],\n' print("生成的代码片段:") print(output)