1
0

Compare commits

...

7 Commits

Author SHA1 Message Date
jzitnik 1c6023beab chore: Added classes to announcement type
Remote Deploy / deploy (push) Successful in 1m26s
2026-06-02 17:13:32 +02:00
jzitnik f559d3a91b fix: No parse
Remote Deploy / deploy (push) Successful in 1m20s
2026-06-02 16:04:31 +02:00
jzitnik 1e971a0601 fix: Typo
Remote Deploy / deploy (push) Successful in 1m18s
2026-06-02 15:45:55 +02:00
jzitnik 32b31814e2 feat: Show always annoucements for this week
Remote Deploy / deploy (push) Successful in 1m35s
2026-06-02 12:29:00 +02:00
jzitnik 1f9543909a chore: Test
Remote Deploy / deploy (push) Successful in 1m16s
2026-06-02 12:12:35 +02:00
jzitnik b4118f7b25 chore: possible fix 2026-06-02 12:09:42 +02:00
jzitnik abddc62f8c feat: Announcement API
Remote Deploy / deploy (push) Successful in 2m38s
2026-06-02 11:18:49 +02:00
6 changed files with 100 additions and 14 deletions
+5
View File
@@ -2,5 +2,10 @@ EMAIL=username@spsejecna.cz
PASSWORD=mojesupertajneheslo
SHAREPOINT_URL=https://spsejecnacz.sharepoint.com/:x:/s/nastenka/ESy19K245Y9BouR5ksciMvgBu3Pn_9EaT0fpP8R6MrkEmg
# API for announcing errors and other global stuff for the client
# This server is open-source too, tho I don't recommend hosting it yourself,
# since it is used for global announcements and if you host it yourself, you won't get the latest news.
ANNOUNCEMENT_API=https://announcement.jecnarozvrh.jzitnik.dev
# For the viewer
API_URl=http://localhost:3000
+4
View File
@@ -9,5 +9,9 @@ services:
NODE_ENV: production
EMAIL: username@spsejecna.cz
PASSWORD: mojesupertajneheslo
# API for announcing errors and other global stuff for the client
# This server is open-source too, tho I don't recommend hosting it yourself,
# since it is used for global announcements and if you host it yourself, you won't get the latest news.
ANNOUNCEMENT_API: https://announcement.jecnarozvrh.jzitnik.dev
volumes:
- ./volume:/usr/src/app/volume
+42
View File
@@ -0,0 +1,42 @@
const API_BASE_URL = process.env.ANNOUNCEMENT_API || "http://localhost:3000";
export type Announcement = {
id: number;
text_content?: string;
author: string;
classes: string[];
flags: Flag[];
start_date: string;
end_date: string;
};
export enum Flag {
SHOW_ALL_ENTRIES
}
export type AnnouncementResponse = {
[date: string]: Announcement[];
}
export default async function getAnnouncements(dates: string[]): Promise<AnnouncementResponse> {
if (dates.length === 0) {
return {};
}
const url = new URL(`/v1/announcements/${dates.join(",")}`, API_BASE_URL).toString();
try {
const response = await fetch(url);
const data = await response.json();
if (!response.ok) {
return {};
}
return data;
} catch (e) {
console.error("Some random ahh error:", e);
return {};
}
}
+6 -4
View File
@@ -1,4 +1,4 @@
import fs from "fs"
import fs from "fs/promises"
const CLASSES: string[] = [
"A1a", "A1b", "A1c", "C1a", "C1b", "C1c", "A2", "C2a", "C2b", "C2c", "E2", "C3a", "C3b", "C3c", "E3"
@@ -45,7 +45,7 @@ interface ScheduleData {
status: { lastUpdated: string };
}
export default function generateArchivedV1_V2(): void {
export default async function generateArchivedV1_V2() {
const dates = getCurrentWeekMondayToFriday();
const currentDate = new Date();
const lastUpdated = currentDate.getHours().toString().padStart(2, "0") + ":" + currentDate.getMinutes().toString().padStart(2, "0");
@@ -73,6 +73,8 @@ export default function generateArchivedV1_V2(): void {
data.schedule.push(d);
}
fs.writeFileSync("volume/db/v1.json", JSON.stringify(data, null, 2));
fs.writeFileSync("volume/db/v2.json", JSON.stringify(data, null, 2));
await Promise.all([
fs.writeFile("volume/db/v1.json", JSON.stringify(data, null, 2)),
fs.writeFile("volume/db/v2.json", JSON.stringify(data, null, 2)),
]);
}
+42 -9
View File
@@ -18,6 +18,7 @@ import parseTeachers from "../utils/parseTeachers.js"
import ExcelJS, { Worksheet, Cell, Row, Workbook } from "exceljs"
import JSZip from "jszip";
import { parseStringPromise } from "xml2js";
import getAnnouncements, { Flag } from "../api/announcements.js";
interface ThemeColors {
[key: number]: string | null;
@@ -124,10 +125,20 @@ export default async function parseV3(workbook: Workbook, downloadedFilePath: st
const upcoming = getUpcomingSheets(workbook);
const resolvedDays = groupSheetsByDate(upcoming);
const sheetDates = resolvedDays.map((d) => d.dateKey);
const announcementDates = getWeekDates().concat(sheetDates);
if (new Date().getDay() === 0) {
announcementDates.push(...getWeekDates(7));
}
const announcements = await getAnnouncements([...new Set(announcementDates)]);
const schedule: any = {};
for (const { dateKey, sheet } of resolvedDays) {
const { changes, absence, inWork, takesPlace, reservedRooms } = extractDaySchedule(sheet, teacherMap, themeColors);
const ann = announcements[dateKey];
const allFlags = ann.map(a => a.flags).flat();
const { changes, absence, inWork, takesPlace, reservedRooms } = extractDaySchedule(sheet, teacherMap, themeColors, allFlags);
schedule[dateKey] = {
info: { inWork },
@@ -140,6 +151,7 @@ export default async function parseV3(workbook: Workbook, downloadedFilePath: st
const data = {
status: { lastUpdated: formatNowTime() },
announcements,
schedule,
};
@@ -202,9 +214,9 @@ function groupSheetsByDate(items: ResolvedDay[]) {
// ────────────────────────────────────────────────────────────
//
function extractDaySchedule(sheet: Worksheet, teacherMap: Record<string, string>, themeColors: ThemeColors | null) {
function extractDaySchedule(sheet: Worksheet, teacherMap: Record<string, string>, themeColors: ThemeColors | null, flags: Flag[]) {
return {
changes: extractClassChanges(sheet, themeColors),
changes: extractClassChanges(sheet, themeColors, flags),
absence: extractAbsence(sheet, teacherMap),
inWork: isPripravaSheet(sheet.name.toLowerCase()),
takesPlace: extractTakesPlace(sheet),
@@ -226,7 +238,9 @@ function isPripravaSheet(name: string) {
// ────────────────────────────────────────────────────────────
//
function extractClassChanges(sheet: Worksheet, themeColors: ThemeColors | null) {
function extractClassChanges(sheet: Worksheet, themeColors: ThemeColors | null, flags: Flag[]) {
console.log(flags)
const ignoreColors = flags.includes(Flag.SHOW_ALL_ENTRIES)
const classRegex = /[AEC][0-4][a-c]?\s*\/.*/s;
const prefixRegex = /[AEC][0-4][a-c]?/;
@@ -248,20 +262,20 @@ function extractClassChanges(sheet: Worksheet, themeColors: ThemeColors | null)
classCells.forEach((address, index) => {
const row = sheet.getRow(Number(sheet.getCell(address).row));
changes[classes[index]] = buildLessonArray(row, address, themeColors);
changes[classes[index]] = buildLessonArray(row, address, themeColors, ignoreColors);
});
return changes;
}
function buildLessonArray(row: Row, ignoreAddress: string, themeColors: ThemeColors | null) {
function buildLessonArray(row: Row, ignoreAddress: string, themeColors: ThemeColors | null, ignoreColors: boolean) {
const lessons: (Lesson | null)[] = [];
row.eachCell((cell) => {
if (cell.address === ignoreAddress) return;
const colIndex = letterToNumber(cell.address.replace(/[0-9]/g, ""));
lessons[colIndex] = parseLessonCell(cell, themeColors);
lessons[colIndex] = parseLessonCell(cell, themeColors, ignoreColors);
});
const normalized = Array.from(lessons, (x) => (x === undefined ? null : x));
@@ -270,13 +284,13 @@ function buildLessonArray(row: Row, ignoreAddress: string, themeColors: ThemeCol
return normalized.slice(1, 11);
}
function parseLessonCell(cell: Cell, themeColors: ThemeColors | null): Lesson | null {
function parseLessonCell(cell: Cell, themeColors: ThemeColors | null, ignoreColors: boolean): Lesson | null {
try {
const text = (cell.text || "").trim();
const cleanupRegex = /^úklid\s+(?:\d+\s+)?[A-Za-z]{2}$/;
// @ts-ignore
if (!text || cleanupRegex.test(text) || !cell.fill?.fgColor) return null;
if (!text || cleanupRegex.test(text) || (!cell.fill?.fgColor && !ignoreColors)) return null;
const backgroundColor = resolveCellColor(cell, themeColors);
const foregroundColor = !backgroundColor ? undefined : (
@@ -415,6 +429,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 (