From af67e99c6bd1e4b4992e8cfe3854f177d0d2db3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Sverre=20Lien=20Sell=C3=A6g?= Date: Fri, 8 Jul 2022 23:40:52 +0200 Subject: [PATCH] a bit better msg --- bin/hoopla.mjs | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/bin/hoopla.mjs b/bin/hoopla.mjs index e112f4b..0bead66 100644 --- a/bin/hoopla.mjs +++ b/bin/hoopla.mjs @@ -57,10 +57,10 @@ const updated = (oldEvent, scrapedEvent) => { places = places.filter((place) => { const scrape = place.scraper == 'hoopla'; if (!scrape) { - console.log( - 101, - `Skipping #${place.id} ${place.name}. Reason: Scraper is ${place.scraper}` - ); + // console.log( + // 101, + // `Skipping #${place.id} ${place.name}. Reason: Scraper is ${place.scraper}` + // ); return false; } const now = unix(new Date()); @@ -98,14 +98,14 @@ const updated = (oldEvent, scrapedEvent) => { console.log(123, 'No upcoming events, dead place?'); } for (let payload of payloads) { - let search = await fetch( - `${api}/search/events/?hoopla_id=${payload.hoopla_id}&token=${token}` - ); + let search; + search = `${api}/search/events/?hoopla_id=${payload.hoopla_id}&token=${token}`; + console.log(search); + search = await fetch(search); if (!search.ok) { - console.log(500, await search.text()); + console.log(search.status, 'Search was not OK.', await search.text()); continue; } - search = await search.json(); let new_event = search.length === 0; let old_event; @@ -142,14 +142,23 @@ const updated = (oldEvent, scrapedEvent) => { console.log(201, 'Skip', place.name, payload.name); } } - let res = await fetch(`${api}/places/${place.id}/?token=${token}`, { - method: 'PATCH', - body: JSON.stringify({ - last_scraped: unix(new Date()) - }), - headers - }); - console.log(res.status, `Last scrape at ${place.name} updated.`); + if (payloads.length > 0) { + let res = await fetch(`${api}/places/${place.id}/?token=${token}`, { + method: 'PATCH', + body: JSON.stringify({ + last_scraped: unix(new Date()) + }), + headers + }); + if (res.ok) { + console.log(res.status, `Last scrape at ${place.name} updated.`); + } else { + console.log( + res.status, + `Last scrape at ${place.name} failed to update last update..` + ); + } + } } })();