Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
a300e771ff | |||
438d5d85cd | |||
0c3ffa3560 | |||
fcaf729247 | |||
2f7c089c0b | |||
26a05a8d8c | |||
6a236c5d68 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
||||
node_modules
|
||||
node_modules
|
||||
test.js
|
@ -12,7 +12,7 @@ npm install virtueller-stundenplan
|
||||
|
||||
# Note
|
||||
|
||||
This project in **very early developement**, expect things to break and change.
|
||||
This project in (relatively) early developement, expect some things to break and change.
|
||||
|
||||
# Usage
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
const crypto = require('node:crypto');
|
||||
const { DateTime } = require('luxon');
|
||||
|
||||
class EncryptionHelper {
|
||||
static encryptDataAESGCM(plainText, key) {
|
||||
@ -17,8 +18,9 @@ class EncryptionHelper {
|
||||
}
|
||||
|
||||
static makeEncryptedParameter(username, key) {
|
||||
const timestamp = new Date().toISOString().replace('T', ' ').split('.')[0];
|
||||
const plainText = `${timestamp} ${username}`;
|
||||
const timestamp = DateTime.now().setZone('Europe/Berlin');
|
||||
const tsFormatted = timestamp.toFormat('yyyy-MM-dd HH:mm:ss');
|
||||
const plainText = `${tsFormatted} ${username}`;
|
||||
|
||||
const hash = crypto.createHash('sha256').update(key, 'utf8').digest();
|
||||
const encryptedData = this.encryptDataAESGCM(plainText, hash);
|
||||
|
@ -13,7 +13,7 @@ class VirtuellerStundenplan {
|
||||
this.#password = config.password;
|
||||
if(config.key) this.key = config.key;
|
||||
|
||||
//this.teacherList = config.teachers;
|
||||
this.holidays = config.holidays;
|
||||
}
|
||||
|
||||
async fetchKey(returnKey=false) {
|
||||
@ -53,6 +53,19 @@ class VirtuellerStundenplan {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all classes of the school.
|
||||
*
|
||||
* @returns {String[]}
|
||||
*/
|
||||
async getClassList() {
|
||||
const data = await this.request("RESTKlassenliste.php");
|
||||
return {
|
||||
head: new Head(data.Msg),
|
||||
content: data.Klassen,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all Messages.
|
||||
*
|
||||
@ -189,7 +202,7 @@ class VirtuellerStundenplan {
|
||||
|
||||
const hasContent = /[\da-zA-Z]/.test(JSON.stringify(day));
|
||||
|
||||
res.content[i] = hasContent ? new TimetableDay(day) : null;
|
||||
res.content[i] = hasContent ? new TimetableDay(day, this.holidays) : null;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -3,12 +3,11 @@ const TimetableHour = require("./TimetableHour");
|
||||
class TimetableDay {
|
||||
first = null;
|
||||
last = null;
|
||||
holiday = false;
|
||||
|
||||
constructor(data) {
|
||||
constructor(data, holidays=defaultHolidays) {
|
||||
this.hours = [];
|
||||
|
||||
//console.log(data)
|
||||
|
||||
for (let i = 0; i < data[0].length; i++) {
|
||||
const hour = [
|
||||
data[0][i],
|
||||
@ -16,7 +15,14 @@ class TimetableDay {
|
||||
data[2][i],
|
||||
data[3][i],
|
||||
data[4][i],
|
||||
]
|
||||
];
|
||||
|
||||
const allSame = sameHours(data);
|
||||
|
||||
if(holidays.includes(allSame)) {
|
||||
this.holiday = allSame;
|
||||
return;
|
||||
}
|
||||
|
||||
const hasContent = /[\da-zA-Z]/.test(JSON.stringify(hour));
|
||||
|
||||
@ -28,6 +34,44 @@ class TimetableDay {
|
||||
this.hours[i] = hasContent ? new TimetableHour(hour) : null;
|
||||
}
|
||||
}
|
||||
|
||||
get isHoliday() {
|
||||
return this.holiday !== false;
|
||||
}
|
||||
|
||||
get holidayName() {
|
||||
return this.isHoliday ? this.holiday : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the day only has the same hours (e.g. "-", "Himmelfahrt")
|
||||
*
|
||||
* @param {Array} day (Nested) Day as an array.
|
||||
* @returns {false|string} False if they differ. When not it returns the only existing value.
|
||||
*/
|
||||
const sameHours = day => {
|
||||
// Only include column teacher, subject and room.
|
||||
// Exam always "-", except for when there's exams.
|
||||
day = [day[0], day[1], day[2]];
|
||||
|
||||
const flat = day.flat(); // from [["x","x"]] to ["x","x"]
|
||||
const first = flat[0];
|
||||
return flat.every(val => val === first) ? first : false;
|
||||
};
|
||||
|
||||
const defaultHolidays = [
|
||||
"Sommerferien",
|
||||
"Tag der Deutschen Einheit",
|
||||
"Herbstferien",
|
||||
"Reformationstag",
|
||||
"Weihnachtsferien",
|
||||
"Winterferien",
|
||||
"Osterferien",
|
||||
"Tag der Arbeit",
|
||||
"Himmelfahrt",
|
||||
"Pfingsten",
|
||||
];
|
||||
|
||||
|
||||
module.exports = TimetableDay;
|
12
npm-shrinkwrap.json
generated
12
npm-shrinkwrap.json
generated
@ -1,16 +1,16 @@
|
||||
{
|
||||
"name": "virtueller-stundenplan",
|
||||
"version": "1.0.0",
|
||||
"version": "1.2.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "virtueller-stundenplan",
|
||||
"version": "1.0.0",
|
||||
"version": "1.2.0",
|
||||
"license": "CC-BY-NC-4.0",
|
||||
"dependencies": {
|
||||
"axios": "^1.8.4",
|
||||
"luxon": "^3.5.0"
|
||||
"luxon": "^3.6.1"
|
||||
}
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
@ -256,9 +256,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/luxon": {
|
||||
"version": "3.5.0",
|
||||
"resolved": "https://registry.npmjs.org/luxon/-/luxon-3.5.0.tgz",
|
||||
"integrity": "sha512-rh+Zjr6DNfUYR3bPwJEnuwDdqMbxZW7LOQfUN4B54+Cl+0o5zaU9RJ6bcidfDtC1cWCZXQ+nvX8bf6bAji37QQ==",
|
||||
"version": "3.6.1",
|
||||
"resolved": "https://registry.npmjs.org/luxon/-/luxon-3.6.1.tgz",
|
||||
"integrity": "sha512-tJLxrKJhO2ukZ5z0gyjY1zPh3Rh88Ej9P7jNrZiHMUXHae1yvI2imgOZtL1TO8TW6biMMKfTtAOoEJANgtWBMQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "virtueller-stundenplan",
|
||||
"version": "1.0.0",
|
||||
"version": "1.2.0",
|
||||
"description": "A library to access the data from virtueller-stundenplan.org",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@ -19,6 +19,6 @@
|
||||
"license": "CC-BY-NC-4.0",
|
||||
"dependencies": {
|
||||
"axios": "^1.8.4",
|
||||
"luxon": "^3.5.0"
|
||||
"luxon": "^3.6.1"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user