From c34f4ee1d1fc4244ddd41a73760664a01551b0ce Mon Sep 17 00:00:00 2001 From: jzitnik-dev Date: Tue, 13 Jan 2026 09:48:59 +0100 Subject: [PATCH] fix: Duplicates Idk who tf is duplicating the sheets --- scrape/parse/v1_v2.js | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/scrape/parse/v1_v2.js b/scrape/parse/v1_v2.js index 94e1f87..1cd2dd0 100644 --- a/scrape/parse/v1_v2.js +++ b/scrape/parse/v1_v2.js @@ -22,8 +22,6 @@ export default async function parseV1V2(downloadedFilePath) { await workbook.xlsx.readFile(downloadedFilePath); const teacherMap = await parseTeachers(); - const sheetNames = workbook.worksheets.map((sheet) => sheet.name); - const dateRegex = /^(pondělí|úterý|středa|čtvrtek|pátek|po|út|ut|st|čt|ct|pa|pá)\s+(\d{1,2})\.\s*(\d{1,2})\.\s*(20\d{2})/i; // Get today's date for comparison @@ -34,18 +32,37 @@ export default async function parseV1V2(downloadedFilePath) { const today = getCurrentDateObject(); - const upcomingSheets = sheetNames.filter((name) => { - const match = name.match(dateRegex); - if (!match) return false; + const datedSheets = []; - const day = Number.parseInt(match[2], 10); - const month = Number.parseInt(match[3], 10) - 1; // JavaScript months are 0-indexed - const year = Number.parseInt(match[4], 10); + for (const sheet of workbook.worksheets) { + const match = sheet.name.match(dateRegex); + if (!match) continue; + + const day = parseInt(match[2], 10); + const month = parseInt(match[3], 10) - 1; + const year = parseInt(match[4], 10); const sheetDate = new Date(year, month, day); + if (sheetDate < today) continue; - return sheetDate >= today; - }) + const dateKey = `${year}-${month + 1}-${day}`; + + datedSheets.push({ + sheet, + dateKey, + }); + } + + const sheetsByDate = {}; + for (const item of datedSheets) { + sheetsByDate[item.dateKey] ??= []; + sheetsByDate[item.dateKey].push(item.sheet); + } + + const upcomingSheets = Object.values(sheetsByDate).map((sheets) => { + if (sheets.length === 1) return sheets[0].name; + return (sheets.find((s) => s.state !== "hidden") ?? sheets[0]).name; + }); const final = [];