This commit is contained in:
@@ -24,8 +24,6 @@ export default async function getAnnouncements(dates: string[]): Promise<Announc
|
||||
|
||||
const url = new URL(`/v1/announcements/${dates.join(",")}`, API_BASE_URL).toString();
|
||||
|
||||
console.log("URL", url)
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
|
||||
+1
-1
@@ -27,4 +27,4 @@ export default async function parseThisShit(downloadedFilePath: string) {
|
||||
await parseV3(workbook, downloadedFilePath);
|
||||
}
|
||||
|
||||
// parseThisShit("volume/db/current.xlsx")
|
||||
parseThisShit("volume/db/current.xlsx")
|
||||
|
||||
+30
-3
@@ -124,13 +124,21 @@ export default async function parseV3(workbook: Workbook, downloadedFilePath: st
|
||||
|
||||
const upcoming = getUpcomingSheets(workbook);
|
||||
const resolvedDays = groupSheetsByDate(upcoming);
|
||||
const getDates = resolvedDays.map((d) => 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 (
|
||||
|
||||
Reference in New Issue
Block a user