import re
import glob
import random

html_files = glob.glob('/Applications/XAMPP/xamppfiles/htdocs/bus.online/*.html')

unsplash_ids = [
    "1544620347-c4fd4a3d5957", # Bus
    "1570125909232-eb263c188f7e", # Bus on road
    "1464219789935-c2d999afa27e", # City street
    "1494515843206-8d18bd0cd258", # Travel
    "1469854523086-cc02fe5d8800", # Bus stop
    "1520114878144-6123742a30db", # Traveler
    "1506012787146-f92b2d7d6d96", # Bus terminal
    "1486025126861-6e8e8dc4627d", # Road trip
    "1501446529957-6226bd447c46", # Cityscape
    "1530685932526-48ec92898688", # Highway
    "1569974249117-eef41f9d6c4d", # Bus interior
    "1516705597950-8b655fcbbdf3", # Travel map
    "1516570530756-3c222ffc3272", # Bus driving
    "1499596634789-9b935414d485", # Travel luggage
    "1513220448126-11f819f7fb07", # Bus station
    "1463162705141-9fbaf6a92823", # Travel road
    "1528699633788-424224dc89b5", # Road trip mountains
    "1529156069898-495926c4f0b2", # City bus
    "1488646953014-85cb44e25828", # Travel bag
    "1449844908441-8829872d2607"  # Golden gate
]

for filepath in html_files:
    with open(filepath, 'r') as f:
        content = f.read()
    
    # We replace https://picsum.photos/WIDTH/HEIGHT?random=XXXX
    # With https://images.unsplash.com/photo-ID?w=WIDTH&q=80
    
    def repl(match):
        width = match.group(1)
        img_id = random.choice(unsplash_ids)
        return f"https://images.unsplash.com/photo-{img_id}?auto=format&fit=crop&w={width}&q=80"
    
    content = re.sub(r'https://picsum\.photos/([0-9]+)/[0-9]+\?random=[0-9]+', repl, content)
    
    with open(filepath, 'w') as f:
        f.write(content)

print("Replaced random picsum images with hardcoded bus/travel Unsplash images.")
