From 68442e281bbf392d27017ab8d6c264b9cc975eee Mon Sep 17 00:00:00 2001 From: marsalva Date: Sat, 21 Mar 2026 19:20:43 +0000 Subject: [PATCH] Actualizar robot.js --- robot.js | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/robot.js b/robot.js index 3b4e7b3..d32a7c3 100644 --- a/robot.js +++ b/robot.js @@ -295,16 +295,31 @@ async function runHomeserve(ownerId, user, pass, gremiosDB) { await gotoWithRetry(page, 'https://www.clientes.homeserve.es/cgi-bin/fccgi.exe?w3exec=lista_servicios_total'); await page.waitForTimeout(3000); - const refs = await page.evaluate(() => { - const cells = Array.from(document.querySelectorAll('td')); - const found = []; - cells.forEach(td => { - const match = td.innerText.trim().match(/^15\d{6}$/); - if (match) found.push(match[0]); + // 🛑 NUEVO: Ahora extraemos la referencia Y LOS ICONOS de la misma pasada + const listaConIconos = await page.evaluate(() => { + const results = []; + const rows = Array.from(document.querySelectorAll('table[bgcolor="#FCF4D6"] tr')); + + rows.forEach(tr => { + const firstTd = tr.querySelector('td'); + if (!firstTd) return; + + const textMatch = firstTd.innerText.trim().match(/^15\d{6}$/); + const aMatch = firstTd.querySelector('a') ? firstTd.querySelector('a').innerText.trim().match(/^15\d{6}$/) : null; + const ref = textMatch ? textMatch[0] : (aMatch ? aMatch[0] : null); + + if (ref) { + const hasLock = firstTd.querySelector('img[src*="candado.gif"]') !== null; + const hasEyes = firstTd.querySelector('img[src*="ojos.gif"]') !== null; + results.push({ ref, hasLock, hasEyes }); + } }); - return [...new Set(found)]; + return results; }); + // Sacamos solo los números para la escoba (syncAndArchive) + const refs = [...new Set(listaConIconos.map(item => item.ref))]; + if (refs.length > 0) { await syncAndArchive(ownerId, 'homeserve', refs); } @@ -366,6 +381,13 @@ async function runHomeserve(ownerId, user, pass, gremiosDB) { // 🪄 Arreglamos el nombre ANTES de guardarlo (Solo en HomeServe) scrapData['Nombre Cliente'] = arreglarNombre(scrapData['Nombre Cliente']); + // 🛑 NUEVO: Le inyectamos los iconos que cazamos antes en la lista + const iconInfo = listaConIconos.find(item => item.ref === ref); + if (iconInfo) { + scrapData['has_lock'] = iconInfo.hasLock; + scrapData['has_eyes'] = iconInfo.hasEyes; + } + const idGremioDetectado = clasificarGremio(scrapData['Descripción'], gremiosDB); if (idGremioDetectado) { scrapData['guild_id'] = idGremioDetectado;