import re
import glob

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

for filepath in html_files:
    with open(filepath, 'r') as f:
        content = f.read()
    
    # Replace loremflickr.com/WIDTH/HEIGHT/KEYWORDS?random=X
    # With image.pollinations.ai/prompt/KEYWORDS?width=WIDTH&height=HEIGHT&nologo=true
    
    def repl(match):
        width = match.group(1)
        height = match.group(2)
        # convert 'newyork,city' to 'new%20york%20city' or similar
        keywords = match.group(3).replace(',', '%20').replace(' ', '%20')
        return f"https://image.pollinations.ai/prompt/{keywords}?width={width}&height={height}&nologo=true"
    
    content = re.sub(r'https://loremflickr\.com/([0-9]+)/([0-9]+)/([a-zA-Z0-9,\-_]+)\?random=[0-9]+', repl, content)
    
    with open(filepath, 'w') as f:
        f.write(content)

print("Replaced all LoremFlickr links with Pollinations AI links.")
