From d8713a567656b1ed616f73d62c68a7485c1ee681 Mon Sep 17 00:00:00 2001 From: wolfycz1 <194477237+wolfycz1@users.noreply.github.com> Date: Tue, 17 Mar 2026 10:54:25 +0100 Subject: [PATCH] fix: Another another fucking teacher absence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Žitník --- scrape/utils/parseAbsence.ts | 9 ++++++--- tests/test.ts | 9 +++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/scrape/utils/parseAbsence.ts b/scrape/utils/parseAbsence.ts index 4eae7e5..fbc469c 100644 --- a/scrape/utils/parseAbsence.ts +++ b/scrape/utils/parseAbsence.ts @@ -40,6 +40,9 @@ export interface AbsenceResult { export const parseSpec = (spec: string | null): Spec | null => { if (!spec) return null; + + spec = spec.replace(/\s+/g, ""); + let m; // Handle "6,7" @@ -118,7 +121,7 @@ export default function parseAbsence(input: string, teacherMap: TeacherMap = {}) // 1. Teachers with specific hours (e.g. "Ab 1-4") const teacherListThenSpecRe = - /([A-Za-z]+(?:[,;]\s?[A-Za-z]+)*)(?:\s*)(\d+(?:\+|-\d+|,\d+)?)(?:\.\s*h)?(?![A-Za-z])/g; + /([A-Za-z]+(?:[,;]\s?[A-Za-z]+)*)(?:\s*)(\d+(?:\s*\+|\s*-\s*\d+|\s*,\s*\d+)?)(?:\.\s*h)?(?![A-Za-z])/g; let m; while ((m = teacherListThenSpecRe.exec(s)) !== null) { @@ -157,7 +160,7 @@ export default function parseAbsence(input: string, teacherMap: TeacherMap = {}) } // 1b. Teachers with "-exk" followed by spec (e.g. "Ex-exk. 3+") - const teacherExkWithSpecRe = /([A-Za-z]+)-exk(?:\.)?\s*(\d+(?:\+|-\d+|,\d+)?)/gi; + const teacherExkWithSpecRe = /([A-Za-z]+)-exk(?:\.)?\s*(\d+(?:\s*\+|\s*-\s*\d+|\s*,\s*\d+)?)/gi; while ((m = teacherExkWithSpecRe.exec(s)) !== null) { const matchStart = m.index; const matchEnd = teacherExkWithSpecRe.lastIndex; @@ -251,7 +254,7 @@ export default function parseAbsence(input: string, teacherMap: TeacherMap = {}) } // 5. Bare specs without teacher → invalid - const specOnlyRe = /\b(\d+(?:\+|-\d+|,\d+)?)\b/g; + const specOnlyRe = /\b(\d+(?:\s*\+|\s*-\s*\d+|\s*,\s*\d+)?)\b/g; while ((m = specOnlyRe.exec(s)) !== null) { const matchStart = m.index; if (isConsumed(matchStart)) continue; diff --git a/tests/test.ts b/tests/test.ts index e4daab5..2f223c4 100644 --- a/tests/test.ts +++ b/tests/test.ts @@ -286,6 +286,15 @@ test("Ex-exk. 3", [ }, ]); +test("Su 4 - 6", [ + { + teacher: "MUDr. Kristina Studénková", + teacherCode: "su", + type: "range", + hours: {from: 4, to: 6}, + } +]); + function test(input: string, expectedOutput: any[]) { const res = parseAbsence(input, teachermap);