Files
pfm-ocr/backend/fix_encoding_chars.py
T

34 lines
989 B
Python

import os
import glob
def main():
uploads_dir = "backend/uploads"
if not os.path.exists(uploads_dir):
uploads_dir = "uploads"
manual_pattern = os.path.join(uploads_dir, "manual_label_*.json")
manual_files = glob.glob(manual_pattern)
fixed_count = 0
for mf in manual_files:
try:
with open(mf, "r", encoding="utf-8") as f:
content = f.read()
if "✓" in content:
# Replace with the correct checkmark character
content = content.replace("✓", "✓")
with open(mf, "w", encoding="utf-8") as f:
f.write(content)
print(f"Fixed encoding corruption in: {mf}")
fixed_count += 1
except Exception as e:
print(f"Error fixing {mf}: {e}")
print(f"Encoding fix completed. Files fixed: {fixed_count}")
if __name__ == "__main__":
main()