diff --git a/scrape/api/annoucements.ts b/scrape/api/annoucements.ts index d218781..714adf1 100644 --- a/scrape/api/annoucements.ts +++ b/scrape/api/annoucements.ts @@ -24,8 +24,6 @@ export default async function getAnnouncements(dates: string[]): Promise d.dateKey); - const annoucements = await getAnnouncements(getDates); + + const sheetDates = resolvedDays.map((d) => d.dateKey); + const announcementDates = getWeekDates().concat(sheetDates); + if (new Date().getDay() === 0) { + announcementDates.push(...getWeekDates(7)); + } + const annoucements = await getAnnouncements([...new Set(announcementDates)]); const schedule: any = {}; for (const { dateKey, sheet } of resolvedDays) { - const { changes, absence, inWork, takesPlace, reservedRooms } = extractDaySchedule(sheet, teacherMap, themeColors, annoucements[dateKey]?.map(a => a.flags)?.flat() || []); + const ann = annoucements[dateKey]; + const allFlags = ann.map(a => a.flags).flat(); + + const { changes, absence, inWork, takesPlace, reservedRooms } = extractDaySchedule(sheet, teacherMap, themeColors, allFlags); schedule[dateKey] = { info: { inWork }, @@ -420,6 +428,25 @@ function letterToNumber(letter: string) { return letter.toLowerCase().charCodeAt(0) - 97; } +function getWeekDates(offset: number = 0): string[] { + const today = new Date(); + const day = today.getDay(); + const monday = new Date(today); + monday.setDate(today.getDate() + (day === 0 ? -6 : 1 - day) + offset); + + const dates: string[] = []; + for (let i = 0; i < 5; i++) { + const d = new Date(monday); + d.setDate(monday.getDate() + i); + dates.push(formatDateKey(d)); + } + return dates; +} + +function formatDateKey(date: Date): string { + return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`; +} + function formatNowTime() { const now = new Date(); return (