Actualizar robot.js
This commit is contained in:
36
robot.js
36
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;
|
||||
|
||||
Reference in New Issue
Block a user