This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
const cron = require('node-cron');
|
import cron from 'node-cron';
|
||||||
const { exec } = require('child_process');
|
import { exec } from 'child_process';
|
||||||
const { scheduleRules, toMinutes } = require('./scheduleRules');
|
import { scheduleRules, toMinutes } from './scheduleRules.js';
|
||||||
|
|
||||||
function runScraper() {
|
function runScraper() {
|
||||||
console.log(`Running scraper at ${new Date().toLocaleString()}...`);
|
console.log(`Running scraper at ${new Date().toLocaleString()}...`);
|
||||||
|
|||||||
92
package-lock.json
generated
92
package-lock.json
generated
@@ -13,7 +13,6 @@
|
|||||||
"concurrently": "^9.2.0",
|
"concurrently": "^9.2.0",
|
||||||
"express": "^5.1.0",
|
"express": "^5.1.0",
|
||||||
"node-cron": "^4.2.1",
|
"node-cron": "^4.2.1",
|
||||||
"node-fetch": "^3.3.2",
|
|
||||||
"puppeteer": "^24.10.0",
|
"puppeteer": "^24.10.0",
|
||||||
"xlsx": "^0.18.5"
|
"xlsx": "^0.18.5"
|
||||||
}
|
}
|
||||||
@@ -1019,29 +1018,6 @@
|
|||||||
"pend": "~1.2.0"
|
"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": {
|
"node_modules/finalhandler": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.0.tgz",
|
||||||
@@ -1059,18 +1035,6 @@
|
|||||||
"node": ">= 0.8"
|
"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": {
|
"node_modules/forwarded": {
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||||
@@ -1506,53 +1470,6 @@
|
|||||||
"node": ">=6.0.0"
|
"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": {
|
"node_modules/nth-check": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz",
|
||||||
@@ -2364,15 +2281,6 @@
|
|||||||
"node": ">= 0.8"
|
"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": {
|
"node_modules/whatwg-encoding": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"author": "Jakub Žitník",
|
"author": "Jakub Žitník",
|
||||||
"type": "commonjs",
|
"type": "module",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "concurrently \"node server.js\" \"node cron-runner.js\""
|
"start": "concurrently \"node server.js\" \"node cron-runner.js\""
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
"concurrently": "^9.2.0",
|
"concurrently": "^9.2.0",
|
||||||
"express": "^5.1.0",
|
"express": "^5.1.0",
|
||||||
"node-cron": "^4.2.1",
|
"node-cron": "^4.2.1",
|
||||||
"node-fetch": "^3.3.2",
|
|
||||||
"puppeteer": "^24.10.0",
|
"puppeteer": "^24.10.0",
|
||||||
"xlsx": "^0.18.5"
|
"xlsx": "^0.18.5"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Rules: start and end in 24h format, interval in minutes
|
// Rules: start and end in 24h format, interval in minutes
|
||||||
const scheduleRules = [
|
export const scheduleRules = [
|
||||||
{ start: "0:00", end: "3:00", interval: 180 },
|
{ start: "0:00", end: "3:00", interval: 180 },
|
||||||
{ start: "3:00", end: "4:00", interval: 60 },
|
{ start: "3:00", end: "4:00", interval: 60 },
|
||||||
{ start: "5:00", end: "6:00", interval: 30 },
|
{ start: "5:00", end: "6:00", interval: 30 },
|
||||||
@@ -9,12 +9,12 @@ const scheduleRules = [
|
|||||||
{ start: "19:00", end: "0:00", interval: 180 }
|
{ start: "19:00", end: "0:00", interval: 180 }
|
||||||
];
|
];
|
||||||
|
|
||||||
function toMinutes(timeStr) {
|
export function toMinutes(timeStr) {
|
||||||
const [h, m] = timeStr.split(":").map(Number);
|
const [h, m] = timeStr.split(":").map(Number);
|
||||||
return h * 60 + (m || 0);
|
return h * 60 + (m || 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentInterval(date = new Date()) {
|
export function getCurrentInterval(date = new Date()) {
|
||||||
const nowMinutes = date.getHours() * 60 + date.getMinutes();
|
const nowMinutes = date.getHours() * 60 + date.getMinutes();
|
||||||
|
|
||||||
for (const rule of scheduleRules) {
|
for (const rule of scheduleRules) {
|
||||||
@@ -35,9 +35,3 @@ function getCurrentInterval(date = new Date()) {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
scheduleRules,
|
|
||||||
getCurrentInterval,
|
|
||||||
toMinutes
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const XLSX = require('xlsx');
|
import XLSX from "xlsx";
|
||||||
const fs = require("fs");
|
import fs from "fs";
|
||||||
const parseAbsence = require('./utils/parseAbsence');
|
import parseAbsence from "./utils/parseAbsence.js";
|
||||||
const parseTeachers = require('./utils/parseTeachers');
|
import parseTeachers from "./utils/parseTeachers.js";
|
||||||
|
|
||||||
async function parseThisShit(downloadedFilePath) {
|
export default async function parseThisShit(downloadedFilePath) {
|
||||||
const workbook = XLSX.readFile(downloadedFilePath);
|
const workbook = XLSX.readFile(downloadedFilePath);
|
||||||
const sheetNames = workbook.SheetNames;
|
const sheetNames = workbook.SheetNames;
|
||||||
|
|
||||||
@@ -138,6 +138,4 @@ async function parseThisShit(downloadedFilePath) {
|
|||||||
fs.writeFileSync('db/current.json', JSON.stringify(data));
|
fs.writeFileSync('db/current.json', JSON.stringify(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = parseThisShit;
|
|
||||||
|
|
||||||
// parseThisShit("downloads/table.xlsx");
|
// parseThisShit("downloads/table.xlsx");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const puppeteer = require('puppeteer');
|
import puppeteer from 'puppeteer';
|
||||||
const path = require('path');
|
import path from 'path';
|
||||||
const fs = require('fs');
|
import fs from 'fs';
|
||||||
const parseThisShit = require('./parse');
|
import parseThisShit from './parse.js';
|
||||||
|
|
||||||
const EMAIL = process.env.EMAIL;
|
const EMAIL = process.env.EMAIL;
|
||||||
const PASSWORD = process.env.PASSWORD;
|
const PASSWORD = process.env.PASSWORD;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
function parseAbsence(str, teacherMap) {
|
export default function parseAbsence(str, teacherMap) {
|
||||||
str = str.trim().replace(/\s+/g, " ");
|
str = str.trim().replace(/\s+/g, " ");
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
@@ -40,5 +40,3 @@ function parseAbsence(str, teacherMap) {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = parseAbsence;
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
const cheerio = require("cheerio");
|
import * as cheerio from "cheerio";
|
||||||
const fetch = require("node-fetch");
|
|
||||||
|
|
||||||
globalThis.File = class File {};
|
globalThis.File = class File {};
|
||||||
|
|
||||||
async function parseTeachers() {
|
export default async function parseTeachers() {
|
||||||
const url = "https://spsejecna.cz/ucitel";
|
const url = "https://spsejecna.cz/ucitel";
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const data = await response.text(); // fetch needs .text() to get HTML
|
const data = await response.text(); // fetch needs .text() to get HTML
|
||||||
@@ -24,5 +23,3 @@ async function parseTeachers() {
|
|||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = parseTeachers;
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const express = require("express");
|
import express from "express";
|
||||||
const path = require("path");
|
import path from "path";
|
||||||
const app = express();
|
const app = express();
|
||||||
const fs = require("fs/promises");
|
import fs from "fs/promises";
|
||||||
const { getCurrentInterval } = require("./scheduleRules");
|
import { getCurrentInterval } from "./scheduleRules.js";
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user