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 gotoWithRetry(page, 'https://www.clientes.homeserve.es/cgi-bin/fccgi.exe?w3exec=lista_servicios_total');
|
||||||
await page.waitForTimeout(3000);
|
await page.waitForTimeout(3000);
|
||||||
|
|
||||||
const refs = await page.evaluate(() => {
|
// 🛑 NUEVO: Ahora extraemos la referencia Y LOS ICONOS de la misma pasada
|
||||||
const cells = Array.from(document.querySelectorAll('td'));
|
const listaConIconos = await page.evaluate(() => {
|
||||||
const found = [];
|
const results = [];
|
||||||
cells.forEach(td => {
|
const rows = Array.from(document.querySelectorAll('table[bgcolor="#FCF4D6"] tr'));
|
||||||
const match = td.innerText.trim().match(/^15\d{6}$/);
|
|
||||||
if (match) found.push(match[0]);
|
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) {
|
if (refs.length > 0) {
|
||||||
await syncAndArchive(ownerId, 'homeserve', refs);
|
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)
|
// 🪄 Arreglamos el nombre ANTES de guardarlo (Solo en HomeServe)
|
||||||
scrapData['Nombre Cliente'] = arreglarNombre(scrapData['Nombre Cliente']);
|
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);
|
const idGremioDetectado = clasificarGremio(scrapData['Descripción'], gremiosDB);
|
||||||
if (idGremioDetectado) {
|
if (idGremioDetectado) {
|
||||||
scrapData['guild_id'] = idGremioDetectado;
|
scrapData['guild_id'] = idGremioDetectado;
|
||||||
|
|||||||
Reference in New Issue
Block a user