@@ -51,51 +51,57 @@ def run_mobile_tracker():
5151 xml_path = bot .dump_hierarchy ()
5252 inspector = UIInspector (xml_path )
5353
54- # 3. Buscar Precio (Estrategia Mejorada)
55- # Regex para formatos: 1.250.000 / 1,250,000 / 1250000
56- # Evita fechas (2025) y specs simples (128) pidiendo longitud mínima o puntos
57- regex_price = r"[\d]{1,3}(?:[.,]\d{3})+"
54+ # DEBUG: Imprimir todo lo que ve para entender la estructura
55+ logger .info ("--- DUMP DE VISTA (Primeros 50 nodos de texto) ---" )
56+ count = 0
57+ for node in inspector .root .iter ('node' ):
58+ txt = node .attrib .get ('text' , '' ) or node .attrib .get ('content-desc' , '' )
59+ if txt and len (txt ) > 2 : # Ignorar cositas chicas
60+ logger .info (f"[{ count } ] Text: '{ txt } ' | ID: { node .attrib .get ('resource-id' , 'N/A' )} " )
61+ count += 1
62+ if count > 50 : break
63+ logger .info ("------------------------------------------------" )
64+
65+ # 3. Buscar Precio (Estrategia Accesibilidad: "X pesos con Y centavos")
66+ # Capturamos "658424 pesos"
67+ regex_accessible = r"(\d+)\s+pesos"
5868
59- candidates = inspector .find_all_nodes_by_regex (regex_price )
69+ candidates = inspector .find_all_nodes_by_regex (regex_accessible )
6070
6171 price_val = 0.0
6272 found_text = ""
6373
6474 if candidates :
65- logger .info (f"🔎 Encontrados { len (candidates )} candidatos de precio." )
66- best_candidate = None
67- max_price = 0.0
75+ logger .info (f"🔎 Encontrados { len (candidates )} nodos de accesibilidad 'pesos'." )
6876
77+ # Tomamos el primer candidato válido (usualmente el precio principal aparece primero o cerca del botón comprar)
6978 for cand in candidates :
7079 txt = cand ['text' ] or cand ['content_desc' ]
71- val = clean_price (txt )
72- logger .info (f" - Candidato: '{ txt } ' -> { val } " )
73-
74- # Heurística: El precio de un iPhone 15 debe ser alto (> 100000 ARS)
75- # y queremos el valor más alto visible (a menos que haya descuentos mostrando precio anterior)
76- # Pero cuidado con precios tachados.
77- # Por ahora, tomamos el valor válido más alto encontrado como 'Precio Detectado'
78- if val > 100000 and val > max_price :
79- max_price = val
80- best_candidate = cand
81-
82- if best_candidate :
83- price_val = max_price
84- found_text = best_candidate ['text' ] or best_candidate ['content_desc' ]
85- logger .info (f"🎯 Ganador: '{ found_text } '" )
80+ match = re .search (regex_accessible , txt , re .IGNORECASE )
81+ if match :
82+ val_str = match .group (1 )
83+ val = float (val_str )
84+ logger .info (f" - Candidato: '{ txt } ' -> { val } " )
85+
86+ # Descartar precios ridículamente bajos (ej: "0 pesos")
87+ if val > 1000 :
88+ price_val = val
89+ found_text = txt
90+ break # Encontramos el precio principal
8691
8792 if price_val == 0.0 :
88- logger .warning ("Ampliando búsqueda a números simples..." )
89- # Fallback: buscar cualquier número grande sin puntos
90- candidates_simple = inspector .find_all_nodes_by_regex (r"\d{4,}" )
91- for cand in candidates_simple :
92- val = clean_price (cand ['text' ] or cand ['content_desc' ])
93- if val > 100000 : # Filtro de ruido
94- price_val = val
95- found_text = cand ['text' ] or cand ['content_desc' ]
96- break
93+ logger .warning ("⚠️ Falló patrón 'pesos'. Probando métodos antiguos..." )
94+ # Fallback 1: Regex numérico clásico ($ 1.250.000)
95+ regex_price = r"\$\s?[\d]{1,3}(?:[.,]\d{3})+"
96+ candidates_v2 = inspector .find_all_nodes_by_regex (regex_price )
97+ # (Lógica simplificada para fallback)
98+ for cand in candidates_v2 :
99+ val = clean_price (cand ['text' ])
100+ if val > 100000 :
101+ price_val = val
102+ break
97103
98- logger .info (f"🏷️ Precio extraído: { price_val } " )
104+ logger .info (f"🏷️ Precio FINAL extraído: { price_val } " )
99105
100106 # 4. Guardar Reporte
101107 data = [{
0 commit comments