Initial commit: 教务系统在线平台
- 包含4个产业方向的前端项目:智能开发、智能制造、大健康、财经商贸 - 已清理node_modules、.yoyo等大文件,项目大小从2.6GB优化至631MB - 配置完善的.gitignore文件 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
140
frontend_智能开发/simplify_content.py
Normal file
140
frontend_智能开发/simplify_content.py
Normal file
@@ -0,0 +1,140 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
def create_backup(file_path):
|
||||
"""创建备份文件"""
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
backup_path = f"{file_path}.backup_{timestamp}"
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
with open(backup_path, 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
print(f"已创建备份: {backup_path}")
|
||||
return backup_path
|
||||
|
||||
def simplify_content_structure():
|
||||
"""将content对象简化为只包含原始内容"""
|
||||
file_path = 'src/mocks/resumeInterviewMock.js'
|
||||
|
||||
# 创建备份
|
||||
create_backup(file_path)
|
||||
|
||||
# 有真实修改版的岗位列表(这些要保留original和modified)
|
||||
real_modified_positions = {
|
||||
"会展策划师",
|
||||
"会展执行助理",
|
||||
"会展讲解员",
|
||||
"活动策划师",
|
||||
"活动执行",
|
||||
"漫展策划师",
|
||||
"旅游规划师",
|
||||
"旅游计调专员",
|
||||
"景区运营专员",
|
||||
"文旅运营总监助理"
|
||||
}
|
||||
|
||||
# 读取文件内容
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# 处理模式:
|
||||
# 1. 找到position: "岗位名"
|
||||
# 2. 找到其后的content: {
|
||||
# 3. 如果岗位不在real_modified_positions中,将content: { original: `...`, modified: `...` } 改为 content: `...`
|
||||
|
||||
def process_position_block(match):
|
||||
full_match = match.group(0)
|
||||
position_name = match.group(1)
|
||||
|
||||
if position_name in real_modified_positions:
|
||||
# 保留原样
|
||||
print(f"✓ 保留 {position_name} 的original和modified结构")
|
||||
return full_match
|
||||
|
||||
# 提取original内容
|
||||
original_match = re.search(r'original:\s*`([^`]*)`', full_match, re.DOTALL)
|
||||
if original_match:
|
||||
original_content = original_match.group(1)
|
||||
# 替换整个content对象为简单字符串
|
||||
new_content = re.sub(
|
||||
r'content:\s*\{[^}]*original:\s*`[^`]*`[^}]*modified:\s*`[^`]*`[^}]*\}',
|
||||
f'content: `{original_content}`',
|
||||
full_match,
|
||||
flags=re.DOTALL
|
||||
)
|
||||
print(f"✗ 简化 {position_name} 的content结构(删除modified)")
|
||||
return new_content
|
||||
|
||||
return full_match
|
||||
|
||||
# 匹配position到整个content对象的模式
|
||||
pattern = r'position:\s*"([^"]+)"[^{]*content:\s*\{[^}]*original:\s*`[^`]*`[^}]*modified:\s*`[^`]*`[^}]*\}'
|
||||
|
||||
# 执行替换
|
||||
new_content = re.sub(pattern, process_position_block, content, flags=re.DOTALL)
|
||||
|
||||
# 保存文件
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
f.write(new_content)
|
||||
|
||||
print("\n处理完成!")
|
||||
|
||||
def verify_results():
|
||||
"""验证结果"""
|
||||
file_path = 'src/mocks/resumeInterviewMock.js'
|
||||
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# 统计还有modified字段的岗位
|
||||
pattern = r'position:\s*"([^"]+)"[^}]*modified:\s*`'
|
||||
matches = re.findall(pattern, content, re.DOTALL)
|
||||
|
||||
print("\n验证结果:")
|
||||
print("=" * 50)
|
||||
print(f"还有modified字段的岗位(共{len(set(matches))}个):")
|
||||
for position in set(matches):
|
||||
print(f" - {position}")
|
||||
|
||||
# 期望的列表
|
||||
expected = {
|
||||
"会展策划师",
|
||||
"会展执行助理",
|
||||
"会展讲解员",
|
||||
"活动策划师",
|
||||
"活动执行",
|
||||
"漫展策划师",
|
||||
"旅游规划师",
|
||||
"旅游计调专员",
|
||||
"景区运营专员",
|
||||
"文旅运营总监助理"
|
||||
}
|
||||
|
||||
found = set(matches)
|
||||
|
||||
if found == expected:
|
||||
print("\n✓ 完美!所有岗位的modified字段都正确")
|
||||
else:
|
||||
missing = expected - found
|
||||
extra = found - expected
|
||||
|
||||
if missing:
|
||||
print(f"\n⚠️ 缺少modified的岗位:{missing}")
|
||||
if extra:
|
||||
print(f"\n⚠️ 不应该有modified的岗位:{extra}")
|
||||
|
||||
def main():
|
||||
print("开始简化content结构...")
|
||||
print("=" * 50)
|
||||
|
||||
# 简化content结构
|
||||
simplify_content_structure()
|
||||
|
||||
# 验证结果
|
||||
verify_results()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user