import sys file_path = r"c:\Users\lapet\github-all\darkmedia\.youtube\scripts\firefly_horror_bot.py" try: with open(file_path, "r", encoding="utf-8") as f: text = f.read() # Attempt to reverse the double-encoding # If the text was UTF-8 interpreted as Latin-1 and saved as UTF-8: # We encode to Latin-1 to get the original UTF-8 bytes, then decode as UTF-8 original_bytes = text.encode("latin-1") fixed_text = original_bytes.decode("utf-8") # If successful, save it back with open(file_path, "w", encoding="utf-8") as f: f.write(fixed_text) print("SUCCESS: File was double-encoded and has now been repaired.") except Exception as e: print(f"FAILED to repair: {e}") # If latin-1 fails, maybe cp1252 with a fallback? try: original_bytes = text.encode("cp1252", errors="replace") fixed_text = original_bytes.decode("utf-8", errors="replace") with open(file_path, "w", encoding="utf-8") as f: f.write(fixed_text) print("SUCCESS (with replace): File was repaired using cp1252 fallback.") except Exception as e2: print(f"Completely failed: {e2}")