import os, glob

count = 0
for path in glob.glob('templates/**/*.html', recursive=True):
    with open(path, 'r', encoding='utf-8') as f:
        content = f.read()
    
    # Target exactly what we are patching
    new_content = content.replace("url_for('static', filename=img(", "url_for('serve_media', filename=img(")
    
    if new_content != content:
        with open(path, 'w', encoding='utf-8') as f:
            f.write(new_content)
        print(f'Updated {path}')
        count += 1

print(f'Done replacing in {count} files')
