This commit is contained in:
+4
-2
@@ -14,14 +14,16 @@
|
||||
|
||||
import ExcelJS from "exceljs"
|
||||
|
||||
import parseV1V2 from "./parse/v1_v2.js";
|
||||
//import parseV1V2 from "./parse/v1_v2.js";
|
||||
import parseV3 from "./parse/v3.js";
|
||||
import generateArchivedV1_V2 from "./parse/archived/v1_v2.js";
|
||||
|
||||
export default async function parseThisShit(downloadedFilePath: string) {
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
await workbook.xlsx.readFile(downloadedFilePath);
|
||||
|
||||
await parseV1V2(workbook);
|
||||
//await parseV1V2(workbook);
|
||||
await generateArchivedV1_V2();
|
||||
await parseV3(workbook, downloadedFilePath);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import fs from "fs"
|
||||
|
||||
const CLASSES: string[] = [
|
||||
"A1a", "A1b", "A1c", "C1a", "C1b", "C1c", "A2", "C2a", "C2b", "C2c", "E2", "C3a", "C3b", "C3c", "E3"
|
||||
];
|
||||
|
||||
function formatDate(date: Date): string {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, "0");
|
||||
const day = String(date.getDate()).padStart(2, "0");
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
const EXAMPLE_SCHEDULE: (string | null)[] = [
|
||||
"Verze 1 API bude ukončena",
|
||||
"Prosím aktualizujte si aplikaci.",
|
||||
"Po ukončení Vám nebude fungovat",
|
||||
"mimořádný rozvrh.",
|
||||
null,
|
||||
"Pokud jste vývojář aplikace,",
|
||||
"podívejte se na dokumentaci na",
|
||||
"jecnarozvrh.jzitnik.dev",
|
||||
null,
|
||||
null
|
||||
];
|
||||
|
||||
function getCurrentWeekMondayToFriday(referenceDate: Date = new Date()): string[] {
|
||||
const date = new Date(referenceDate);
|
||||
const day = date.getDay();
|
||||
const diffToMonday = day === 0 ? -6 : 1 - day;
|
||||
const monday = new Date(date);
|
||||
monday.setDate(date.getDate() + diffToMonday);
|
||||
const week: string[] = [];
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const d = new Date(monday);
|
||||
d.setDate(monday.getDate() + i);
|
||||
week.push(formatDate(d));
|
||||
}
|
||||
return week;
|
||||
}
|
||||
|
||||
interface ScheduleData {
|
||||
schedule: Record<string, (string | null)[]>[];
|
||||
props: { date: string; priprava: boolean }[];
|
||||
status: { lastUpdated: string };
|
||||
}
|
||||
|
||||
export default function generateArchivedV1_V2(): void {
|
||||
const dates = getCurrentWeekMondayToFriday();
|
||||
const currentDate = new Date();
|
||||
const lastUpdated = currentDate.getHours().toString().padStart(2, "0") + ":" + currentDate.getMinutes().toString().padStart(2, "0");
|
||||
|
||||
const data: ScheduleData = {
|
||||
schedule: [],
|
||||
props: [],
|
||||
status: {
|
||||
lastUpdated
|
||||
}
|
||||
};
|
||||
|
||||
for (const date of dates) {
|
||||
data.props.push({
|
||||
date,
|
||||
priprava: false
|
||||
});
|
||||
|
||||
const d: Record<string, (string | null)[]> = {};
|
||||
|
||||
for (const cls of CLASSES) {
|
||||
d[cls] = EXAMPLE_SCHEDULE;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
Reference in New Issue
Block a user