1
0

feat: Convert to modules
All checks were successful
Remote Deploy / deploy (push) Successful in 3s

This commit is contained in:
2025-08-31 16:48:40 +02:00
parent 1a29836e44
commit c82fef9e4f
9 changed files with 23 additions and 129 deletions

View File

@@ -1,6 +1,6 @@
const cron = require('node-cron');
const { exec } = require('child_process');
const { scheduleRules, toMinutes } = require('./scheduleRules');
import cron from 'node-cron';
import { exec } from 'child_process';
import { scheduleRules, toMinutes } from './scheduleRules.js';
function runScraper() {
console.log(`Running scraper at ${new Date().toLocaleString()}...`);

92
package-lock.json generated
View File

@@ -13,7 +13,6 @@
"concurrently": "^9.2.0",
"express": "^5.1.0",
"node-cron": "^4.2.1",
"node-fetch": "^3.3.2",
"puppeteer": "^24.10.0",
"xlsx": "^0.18.5"
}
@@ -1019,29 +1018,6 @@
"pend": "~1.2.0"
}
},
"node_modules/fetch-blob": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/jimmywarting"
},
{
"type": "paypal",
"url": "https://paypal.me/jimmywarting"
}
],
"license": "MIT",
"dependencies": {
"node-domexception": "^1.0.0",
"web-streams-polyfill": "^3.0.3"
},
"engines": {
"node": "^12.20 || >= 14.13"
}
},
"node_modules/finalhandler": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.0.tgz",
@@ -1059,18 +1035,6 @@
"node": ">= 0.8"
}
},
"node_modules/formdata-polyfill": {
"version": "4.0.10",
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
"license": "MIT",
"dependencies": {
"fetch-blob": "^3.1.2"
},
"engines": {
"node": ">=12.20.0"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@@ -1506,53 +1470,6 @@
"node": ">=6.0.0"
}
},
"node_modules/node-domexception": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==",
"deprecated": "Use your platform's native DOMException instead",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/jimmywarting"
},
{
"type": "github",
"url": "https://paypal.me/jimmywarting"
}
],
"license": "MIT",
"engines": {
"node": ">=10.5.0"
}
},
"node_modules/node-fetch": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
"integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
"license": "MIT",
"dependencies": {
"data-uri-to-buffer": "^4.0.0",
"fetch-blob": "^3.1.4",
"formdata-polyfill": "^4.0.10"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/node-fetch"
}
},
"node_modules/node-fetch/node_modules/data-uri-to-buffer": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==",
"license": "MIT",
"engines": {
"node": ">= 12"
}
},
"node_modules/nth-check": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz",
@@ -2364,15 +2281,6 @@
"node": ">= 0.8"
}
},
"node_modules/web-streams-polyfill": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz",
"integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==",
"license": "MIT",
"engines": {
"node": ">= 8"
}
},
"node_modules/whatwg-encoding": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz",

View File

@@ -4,7 +4,7 @@
"description": "",
"license": "ISC",
"author": "Jakub Žitník",
"type": "commonjs",
"type": "module",
"main": "server.js",
"scripts": {
"start": "concurrently \"node server.js\" \"node cron-runner.js\""
@@ -14,7 +14,6 @@
"concurrently": "^9.2.0",
"express": "^5.1.0",
"node-cron": "^4.2.1",
"node-fetch": "^3.3.2",
"puppeteer": "^24.10.0",
"xlsx": "^0.18.5"
}

View File

@@ -1,5 +1,5 @@
// Rules: start and end in 24h format, interval in minutes
const scheduleRules = [
export const scheduleRules = [
{ start: "0:00", end: "3:00", interval: 180 },
{ start: "3:00", end: "4:00", interval: 60 },
{ start: "5:00", end: "6:00", interval: 30 },
@@ -9,12 +9,12 @@ const scheduleRules = [
{ start: "19:00", end: "0:00", interval: 180 }
];
function toMinutes(timeStr) {
export function toMinutes(timeStr) {
const [h, m] = timeStr.split(":").map(Number);
return h * 60 + (m || 0);
}
function getCurrentInterval(date = new Date()) {
export function getCurrentInterval(date = new Date()) {
const nowMinutes = date.getHours() * 60 + date.getMinutes();
for (const rule of scheduleRules) {
@@ -35,9 +35,3 @@ function getCurrentInterval(date = new Date()) {
return null;
}
module.exports = {
scheduleRules,
getCurrentInterval,
toMinutes
};

View File

@@ -1,9 +1,9 @@
const XLSX = require('xlsx');
const fs = require("fs");
const parseAbsence = require('./utils/parseAbsence');
const parseTeachers = require('./utils/parseTeachers');
import XLSX from "xlsx";
import fs from "fs";
import parseAbsence from "./utils/parseAbsence.js";
import parseTeachers from "./utils/parseTeachers.js";
async function parseThisShit(downloadedFilePath) {
export default async function parseThisShit(downloadedFilePath) {
const workbook = XLSX.readFile(downloadedFilePath);
const sheetNames = workbook.SheetNames;
@@ -138,6 +138,4 @@ async function parseThisShit(downloadedFilePath) {
fs.writeFileSync('db/current.json', JSON.stringify(data));
}
module.exports = parseThisShit;
// parseThisShit("downloads/table.xlsx");

View File

@@ -1,7 +1,7 @@
const puppeteer = require('puppeteer');
const path = require('path');
const fs = require('fs');
const parseThisShit = require('./parse');
import puppeteer from 'puppeteer';
import path from 'path';
import fs from 'fs';
import parseThisShit from './parse.js';
const EMAIL = process.env.EMAIL;
const PASSWORD = process.env.PASSWORD;

View File

@@ -1,4 +1,4 @@
function parseAbsence(str, teacherMap) {
export default function parseAbsence(str, teacherMap) {
str = str.trim().replace(/\s+/g, " ");
const result = {
@@ -40,5 +40,3 @@ function parseAbsence(str, teacherMap) {
return result;
}
module.exports = parseAbsence;

View File

@@ -1,9 +1,8 @@
const cheerio = require("cheerio");
const fetch = require("node-fetch");
import * as cheerio from "cheerio";
globalThis.File = class File {};
async function parseTeachers() {
export default async function parseTeachers() {
const url = "https://spsejecna.cz/ucitel";
const response = await fetch(url);
const data = await response.text(); // fetch needs .text() to get HTML
@@ -24,5 +23,3 @@ async function parseTeachers() {
return map;
}
module.exports = parseTeachers;

View File

@@ -1,8 +1,8 @@
const express = require("express");
const path = require("path");
import express from "express";
import path from "path";
const app = express();
const fs = require("fs/promises");
const { getCurrentInterval } = require("./scheduleRules");
import fs from "fs/promises";
import { getCurrentInterval } from "./scheduleRules.js";
const PORT = process.env.PORT || 3000;