import os
import re

d = '.'
# Use pipe characters instead of middot to avoid encoding issues on Windows
t = '<title>Anjaneyulu.in | Loans | Fin | Tech | Legal | Govt | Real Estate</title>'

fs = [f for f in os.listdir(d) if f.endswith('.html')]

for f in fs:
    p = os.path.join(d, f)
    with open(p, 'r', encoding='utf-8') as file:
        c = file.read()
    
    # Replace broken title or existing title
    c = re.sub(r'<title>.*?</title>', t, c, flags=re.I|re.S)
    
    # Replace broken og:title or existing og:title
    c = re.sub(
        r'<meta property="og:title" content=".*?">', 
        '<meta property="og:title" content="Anjaneyulu.in | Loans | Fin | Tech | Legal | Govt | Real Estate">', 
        c, 
        flags=re.I
    )
    
    with open(p, 'w', encoding='utf-8') as file:
        file.write(c)

print(f'Updated {len(fs)} files with clean ASCII characters')
