import re filepath = "/home/nexus/ultraconnect/Tars-AI-Assistant/tars_utils.py" with open(filepath, "r", encoding="utf-8") as f: lines = f.readlines() # On cherche la ligne qui contient la fonction "obter_clima" # et on nettoie les 4 lignes suivantes si elles contiennent "try:" sans except. new_lines = [] skip_until_index = -1 for i, line in enumerate(lines): if i <= skip_until_index: continue # Détecte la ligne du commentaire de la docstring if "Busca o clima de Curitiba" in line: # Regarde la ligne précédente, si c'est "try:" orphelin, on le vire if new_lines and new_lines[-1].strip() == "try:": new_lines.pop() # Supprime le try orphelin # Ajoute la docstring propre new_lines.append(line) continue # Si on voit un try: suivi IMMÉDIATEMENT d'une docstring (ce qui est illégal) # On supprime le try if line.strip() == "try:" and i + 1 < len(lines) and '"""' in lines[i+1]: continue new_lines.append(line) # Réécriture with open(filepath, "w", encoding="utf-8") as f: f.writelines(new_lines) print("✅ Fichier tars_utils.py réparé (try orphelin supprimé).")