import os def fix_content(content): replacements = { 'á': 'á', 'ã': 'ã', 'ê': 'ê', 'ç': 'ç', 'ó': 'ó', 'í': 'í', 'ú': 'ú', 'é': 'é', 'ô': 'ô', 'À': 'À', 'É': 'É', 'Ó': 'Ó', 'Ú': 'Ú', 'Â': 'Â', 'Ç': 'Ç', 'Ã': 'Ã', 'õ': 'õ', 'à ': 'à', 'è': 'è', 'ì': 'ì', 'ò': 'ò', 'ù': 'ù', 'ñ': 'ñ', 'Ñ': 'Ñ' } # Double encoding fixes double_replacements = { 'á': 'á', 'ã': 'ã', 'ó': 'ó', 'ê': 'ê', 'ç': 'ç', 'é': 'é', 'í': 'í', 'ú': 'ú', 'ô': 'ô', '├â┬¡': 'í', 'Ãâ¡': 'á', 'Ãâ£': 'ã', 'Ãâ³': 'ó', 'Ãâª': 'ê', 'Ãâ§': 'ç' } for old, new in double_replacements.items(): content = content.replace(old, new) for old, new in replacements.items(): content = content.replace(old, new) return content def process_directory(directory): for root, dirs, files in os.walk(directory): for file in files: if file.endswith(('.tsx', '.ts', '.js', '.jsx')): path = os.path.join(root, file) try: with open(path, 'r', encoding='utf-8') as f: content = f.read() fixed = fix_content(content) if fixed != content: print(f"Corrigindo: {path}") with open(path, 'w', encoding='utf-8') as f: f.write(fixed) except UnicodeDecodeError: try: with open(path, 'r', encoding='latin-1') as f: content = f.read() fixed = fix_content(content) print(f"Corrigindo (latin-1): {path}") with open(path, 'w', encoding='utf-8') as f: f.write(fixed) except Exception as e: print(f"Erro em {path}: {e}") if __name__ == "__main__": process_directory(r"C:\dev\saveinmed\frontend\src") process_directory(r"C:\dev\saveinmed\saveinmed-frontend\src")