From 858d41d772c818ff5bbe705b0191980f2249636a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Zieren?= Date: Thu, 17 Nov 2022 17:00:45 +0100 Subject: [PATCH] Fix failure when parsing inquiries --- main.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/main.js b/main.js index 162dc1d..789ce9c 100644 --- a/main.js +++ b/main.js @@ -391,17 +391,14 @@ function buildEmailsForThreads(teachers, processedThreads, emails) { async function readInquiries(page) { await page.goto(CONFIG.elternportal.url + '/meldungen/kommunikation'); const inquiries = await page.$$eval( - 'h3.panel-title', (headings) => headings.map((h) => { + 'div.panel', (panels) => panels.map(p => { return { - subject: h.textContent.trim().replace(/\(Beantwortet\) (?=\d\d\.\d\d\.\d\d\d\d)/, '') + subject: p.querySelector('h3.panel-title') + .textContent.trim().replace(/\(Beantwortet\) (?=\d\d\.\d\d\.\d\d\d\d)/, ''), + messages: Array.from(p.querySelector('div.panel-body').childNodes) + .filter(n => n.nodeName === '#text').map(n => n.textContent) }; })); - for (let i = 0; i < inquiries.length; ++i) { - inquiries[i].messages = await page.$eval('div#bear_' + i, - (div) => Array.from(div.firstElementChild.childNodes) - .filter(c => c.nodeName === '#text') - .map(c => c.textContent)); - } LOG.info('Found %d inquiries', inquiries.length); // Order is reverse chronological, make it forward. return inquiries.reverse();