import re
import time

timestamp = int(time.time())
cache_buster = f"?v={timestamp}"

# Update index.html
with open('/var/www/html/undangan_digital/index.html', 'r') as f:
    html = f.read()

# Replace any existing ?v=... just in case
html = re.sub(r'(assets/[a-zA-Z0-9_]+\.(?:png|jpg|jpeg|gif|svg))(\?v=\d+)?', r'\1' + cache_buster, html)

with open('/var/www/html/undangan_digital/index.html', 'w') as f:
    f.write(html)

# Update style.css
with open('/var/www/html/undangan_digital/style.css', 'r') as f:
    css = f.read()

css = re.sub(r'(assets/[a-zA-Z0-9_]+\.(?:png|jpg|jpeg|gif|svg))(\?v=\d+)?', r'\1' + cache_buster, css)

with open('/var/www/html/undangan_digital/style.css', 'w') as f:
    f.write(css)

print("Cache buster applied successfully.")
