From e78ee594a06a0d3bbc4e8d753f2b3874f8a0f3e6 Mon Sep 17 00:00:00 2001 From: jzitnik-dev Date: Fri, 30 Jan 2026 19:18:04 +0100 Subject: [PATCH] chore: Idk --- scrape/parse.js | 4 +++- scrape/parse/v3.js | 43 +++++++++++++++++++++++++++++++++++ scripts/loadstaticschedule.js | 14 ++++++++++++ scripts/setup.js | 28 +++++++++++++++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 scrape/parse/v3.js create mode 100644 scripts/setup.js diff --git a/scrape/parse.js b/scrape/parse.js index a4bb495..27c5bf5 100644 --- a/scrape/parse.js +++ b/scrape/parse.js @@ -13,7 +13,9 @@ */ import parseV1V2 from "./parse/v1_v2.js"; +import parseV3 from "./parse/v3.js"; export default async function parseThisShit(downloadedFilePath) { - await parseV1V2(downloadedFilePath) + await parseV1V2(downloadedFilePath); + await parseV3("db/v2.json"); // NEEDS TO BE RAN AFTER V2 (uses its format) } diff --git a/scrape/parse/v3.js b/scrape/parse/v3.js new file mode 100644 index 0000000..53ff708 --- /dev/null +++ b/scrape/parse/v3.js @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2025 Jakub Žitník + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +import parseTeachers from "../utils/parseTeachers.js" +import fs from "fs/promises"; + +const PREVIOUS = "db/v3/_previous.json"; + +export default async function parseV3(fileV2Path) { + const previousStr = fs.readFile(PREVIOUS, { + encoding: "utf8", + }); + const nowStr = fs.readFile(fileV2Path, { + encoding: "utf8", + }) + + const previous = JSON.parse(previousStr); + const previousDays = previous.props.map(prop => prop.date); + const now = JSON.parse(nowStr); + + for (const prop of now.props) { + if (!previousDays.includes(prop.date)) { + doWholeDay(prop); + continue; + } + + // TODO: Check for changes for each class, if any change is do the class (will do someday) + } + + // CHANGE PREVIOUS TO NOW + fs.copyFile(fileV2Path, PREVIOUS); +} diff --git a/scripts/loadstaticschedule.js b/scripts/loadstaticschedule.js index 6d48ede..e022735 100644 --- a/scripts/loadstaticschedule.js +++ b/scripts/loadstaticschedule.js @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2025 Jakub Žitník + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + import axios from "axios"; import { CookieJar } from "tough-cookie"; import { wrapper } from "axios-cookiejar-support"; diff --git a/scripts/setup.js b/scripts/setup.js new file mode 100644 index 0000000..a038175 --- /dev/null +++ b/scripts/setup.js @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2025 Jakub Žitník + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +import fs from "fs"; + +const DIRS = [ + "db/persistent", + "db/v3", +]; + +for (const dir of DIRS) { + try { + fs.mkdirSync(dir); + } catch {} +} + +// LEAVE ME ALONE I KNOW THIS CODE IS SHIT