Files
Investidor-V2/tools/portal-consumer-print-encoding-repair.py
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

21 lines
976 B
Python

from pathlib import Path
import hashlib
root=Path(__file__).resolve().parent.parent
path=root/'resources/js/pages/land-assistance/print.tsx'
original=path.read_text(encoding='utf-8')
if 'Terra e DUAT â€' not in original:
raise SystemExit('Already repaired or source changed; no repeated transcoding.')
encoded=bytearray()
for char in original:
try: encoded.extend(char.encode('cp1252'))
except UnicodeEncodeError:
if ord(char)<=255: encoded.append(ord(char))
else: raise
corrected=encoded.decode('utf-8')
assert 'Terra e DUAT — dados preenchidos pelo requerente' in corrected
assert 'Localização e situação declaradas' in corrected
private=root/'storage/app/private/investmoz-v2/portal-audit'
(private/'land-print-before-c91.tsx').write_bytes(path.read_bytes())
path.write_text(corrected,encoding='utf-8')
print('C91: repaired only the confirmed UTF-8 encoding corruption in the land print component; original source retained privately.')