import os
import shutil
from pathlib import Path

# 定义路径
src_assets_dir = Path(r'C:\Users\jerry\PyCharmProjects\footviz\footviz-vue\src\assets\team_data_html')
public_static_dir = Path(r'C:\Users\jerry\PyCharmProjects\footviz\footviz-vue\public\static\team_data_html')

# 简化文件名映射
team_name_mapping = {
    "Arsenal": "arsenal",
    "Aston Villa": "astonvilla", 
    "Bournemouth": "bournemouth",
    "Brentford": "brentford",
    "Brighton": "brighton",
    "Chelsea": "chelsea",
    "Crystal Palace": "crystalpalace",
    "Everton": "everton",
    "Fulham": "fulham",
    "Ipswich": "ipswich",
    "Leicester": "leicester",
    "Liverpool": "liverpool",
    "Manchester City": "manchestercity",
    "Manchester United": "manchesterunited",
    "Newcastle": "newcastle",
    "Nottingham Forest": "nottinghamforest",
    "Southampton": "southampton",
    "Tottenham": "tottenham",
    "West Ham": "westham",
    "Wolves": "wolves"
}

def simplify_filenames(directory):
    """简化指定目录下的文件名"""
    print(f"处理目录: {directory}")
    
    if not directory.exists():
        print(f"目录 {directory} 不存在")
        return
    
    for old_filename in os.listdir(directory):
        if old_filename.endswith('_goals_vs_assists.html'):
            # 提取球队名
            team_name = old_filename.replace('_goals_vs_assists.html', '')
            
            # 获取新文件名
            if team_name in team_name_mapping:
                new_filename = f"{team_name_mapping[team_name]}.html"
                old_path = directory / old_filename
                new_path = directory / new_filename
                
                # 重命名文件
                os.rename(old_path, new_path)
                print(f"  重命名: {old_filename} -> {new_filename}")
            else:
                print(f"  跳过: {old_filename} (未在映射中找到)")

# 处理两个目录
simplify_filenames(src_assets_dir)
simplify_filenames(public_static_dir)

print("\n文件名简化完成!")