import os
import shutil
import re

src_dir = r"C:\Users\Abhiram P M\Desktop\fwdphotos (4)"
dst_dir = r"d:\iss\Franciscan Society\assets\images\friars"
os.makedirs(dst_dir, exist_ok=True)

copied = {}
for f in os.listdir(src_dir):
    if f.lower().endswith(('.png', '.jpg', '.jpeg')):
        # Clean name, e.g. "1. Br. Santosh Toppo.png" -> "br-santosh-toppo.png"
        clean = re.sub(r'^\d+\.\s*', '', f)
        clean_key = re.sub(r'\.[^.]+$', '', clean).strip()
        
        # Save to assets/images/friars/
        dst_filename = re.sub(r'[^a-zA-Z0-9]', '-', clean_key.lower()) + os.path.splitext(f)[1].lower()
        dst_filename = re.sub(r'-+', '-', dst_filename).strip('-')
        
        src_path = os.path.join(src_dir, f)
        dst_path = os.path.join(dst_dir, dst_filename)
        shutil.copy2(src_path, dst_path)
        
        copied[clean_key] = f"assets/images/friars/{dst_filename}"
        print(f"Copied '{f}' -> '{copied[clean_key]}' (Key: '{clean_key}')")

print(f"\nTotal copied: {len(copied)}")
