Skip to content

Commit 291aeb1

Browse files
committed
Se normalizan textos antes de enviar al formulario
1 parent 3c25578 commit 291aeb1

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

index.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import sys
22
import time
33
import json
4+
import unicodedata
45
from playwright.sync_api import sync_playwright, expect
56

67
def wait(seconds: float, msg: str = ""):
78
if msg:
89
print(f"[WAIT] {msg} ({seconds}s)")
910
time.sleep(seconds)
1011

12+
def normalize_address_text(text: str) -> str:
13+
"""Normalize input by removing accents, converting to uppercase, and cleaning spaces."""
14+
text = unicodedata.normalize("NFD", text)
15+
text = text.encode("ascii", "ignore").decode("utf-8")
16+
text = text.upper().strip()
17+
return " ".join(text.split())
18+
1119
def autocomplete_select(page, selector: str, value: str):
1220
page.click(selector)
1321
wait(0.5)
@@ -38,6 +46,12 @@ def ensure_number_filled(page, selector: str, value: str):
3846

3947
def get_postal_code(commune: str, street: str, number: str) -> dict:
4048
print(f"[INFO] Lookup started for commune='{commune}', street='{street}', number='{number}'")
49+
50+
# Normalize all input values before sending to Correos
51+
commune = normalize_address_text(commune)
52+
street = normalize_address_text(street)
53+
number = normalize_address_text(number)
54+
4155
browser = None
4256
page = None
4357

0 commit comments

Comments
 (0)