diff options
author | RaindropsSys <contact@minteck.org> | 2023-06-22 23:06:12 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-06-22 23:06:12 +0200 |
commit | 23563c7188e089929b60f9e10721c6fc43a220ff (patch) | |
tree | edfe2b009c82900d4ac27db02222d2f68dcad846 /includes/external/school/index.js | |
parent | 7a7a49332df7c852abbaa33c7e8e87f93d064d61 (diff) | |
download | pluralconnect-23563c7188e089929b60f9e10721c6fc43a220ff.tar.gz pluralconnect-23563c7188e089929b60f9e10721c6fc43a220ff.tar.bz2 pluralconnect-23563c7188e089929b60f9e10721c6fc43a220ff.zip |
Updated 15 files, added includes/maintenance/deleteUnusedAssets.php and deleted 4944 files (automated)
Diffstat (limited to 'includes/external/school/index.js')
-rw-r--r-- | includes/external/school/index.js | 207 |
1 files changed, 0 insertions, 207 deletions
diff --git a/includes/external/school/index.js b/includes/external/school/index.js deleted file mode 100644 index 00f3435..0000000 --- a/includes/external/school/index.js +++ /dev/null @@ -1,207 +0,0 @@ -const axios = require('axios'); -const pronote = require('pronote-api'); -const config = require('../../app.json'); - -const url = config.pronote.url; -const username = config.pronote.user; -const password = config.pronote.password; - -process.on('unhandledRejection', (e) => { - console.error(e); - process.exit(2); -}) - -async function getTimetable(offset, last) { - const timetable = lessons; - - if (last) { - let list = timetable.filter(i => new Date(i.from.toDateString()).getTime() === new Date(new Date(new Date().toDateString()).getTime() + 86400000 * offset).getTime()).filter(i => !i.isCancelled); - let lastClass = list[list.length - 1]; - - return lastClass ? lastClass["to"] : null; - } else { - let nextClass = timetable.filter(i => new Date(i.from.toDateString()).getTime() === new Date(new Date(new Date().toDateString()).getTime() + 86400000 * offset).getTime()).filter(i => !i.isCancelled)[0]; - - return nextClass ? nextClass["from"] : null; - } -} - -global.wakeUpTime = null; -global.wakeUpTimeDiff = null; -global.sleepTime = null; -global.sleepTimeDiff = null; -global.sleepClockR = null; -global.sleepClockC = null; -global.wakeUpClockC = null; -global.wakeUpClockR = null; -global.firstClassTime = null; -global.firstClassClockC = null; -global.firstClassClockR = null; - -function digits(input) { - if (input < 10) { - return "0" + input; - } else { - return input; - } -} - -global.tzOffset = Math.abs(new Date().getTimezoneOffset() / 60); - -function formatHours(hours) { - return hours >= 24 ? hours - 24 : hours; -} - -async function updateSleepTime(offset) { - let classTime = await getTimetable(offset); - let classTime2 = await getTimetable(offset + 1); - let tzOffset = global.tzOffset; - - if (classTime) { - global.wakeUpTime = new Date(classTime.getTime() - 5100000); - - if (wakeUpTime.getHours() > 8 || (wakeUpTime.getHours() === 8 && wakeUpTime.getMinutes() > 0)) { - global.wakeUpTime = new Date(wakeUpTime.toISOString().split("T")[0] + "T08:00:00+0" + (tzOffset) + ":00"); - } - - if (classTime.toTimeString().split(" ")[0] === "08:00:00") { - global.wakeUpTime = new Date(wakeUpTime.toISOString().split("T")[0] + "T06:30:00+0" + (tzOffset) + ":00"); - } - - if (classTime.toTimeString().split(" ")[0] === "09:00:00") { - global.wakeUpTime = new Date(wakeUpTime.toISOString().split("T")[0] + "T07:00:00+0" + (tzOffset) + ":00"); - } - - if (classTime.toTimeString().split(" ")[0] === "10:00:00") { - global.wakeUpTime = new Date(wakeUpTime.toISOString().split("T")[0] + "T07:00:00+0" + (tzOffset) + ":00"); - } - global.wakeUpClockR = formatHours(wakeUpTime.getUTCHours() + tzOffset) + ":" + digits(wakeUpTime.getUTCMinutes()); - global.wakeUpClockC = formatHours(wakeUpTime.getUTCHours() + (tzOffset - 1)) + ":" + digits(wakeUpTime.getUTCMinutes()); - - global.firstClassTime = classTime; - global.firstClassClockC = formatHours(firstClassTime.getUTCHours() + (tzOffset - 1)) + ":" + digits(firstClassTime.getUTCMinutes()); - global.firstClassClockR = formatHours(firstClassTime.getUTCHours() + tzOffset) + ":" + digits(firstClassTime.getUTCMinutes()); - global.lastClassTime = await getTimetable(offset, true); - } else { - global.wakeUpTime = null; - global.wakeUpClockR = null; - global.wakeUpClockC = null; - - global.firstClassTime = null; - global.firstClassClockC = null; - global.firstClassClockR = null; - - global.lastClassTime = null; - } - - if (classTime2) { - global.wakeUpTime2 = new Date(classTime2.getTime() - 5100000); - - if (wakeUpTime2.getHours() > 8 || (wakeUpTime2.getHours() === 8 && wakeUpTime2.getMinutes() > 0)) { - global.wakeUpTime2 = new Date(wakeUpTime2.toISOString().split("T")[0] + "T08:00:00+0" + (tzOffset) + ":00"); - } - - if (classTime2.toTimeString().split(" ")[0] === "08:00:00") { - global.wakeUpTime2 = new Date(wakeUpTime2.toISOString().split("T")[0] + "T06:30:00+0" + (tzOffset) + ":00"); - } - - if (classTime2.toTimeString().split(" ")[0] === "09:00:00") { - global.wakeUpTime2 = new Date(wakeUpTime2.toISOString().split("T")[0] + "T07:00:00+0" + (tzOffset) + ":00"); - } - - if (classTime2.toTimeString().split(" ")[0] === "10:00:00") { - global.wakeUpTime2 = new Date(wakeUpTime2.toISOString().split("T")[0] + "T07:00:00+0" + (tzOffset) + ":00"); - } - - global.sleepTime = new Date(global.wakeUpTime2.getTime() - 28800000); - - global.sleepClockR = formatHours(sleepTime.getUTCHours() + tzOffset) + ":" + digits(sleepTime.getUTCMinutes()); - global.sleepClockC = formatHours(sleepTime.getUTCHours() + (tzOffset - 1)) + ":" + digits(sleepTime.getUTCMinutes()); - } else { - global.sleepTime = null; - - global.sleepClockR = null; - global.sleepClockC = null; - } -} - -async function display(offset) { - await updateSleepTime(offset); - console.log(new Date(new Date().getTime() + 86400000 * offset).toDateString()) - console.log(" First: " + firstClassTime + " (" + firstClassClockC + ", " + firstClassClockR + ")"); - console.log(" Wake up: " + wakeUpTime + " (" + wakeUpClockC + ", " + wakeUpClockR + ")"); - console.log(" Sleep: " + sleepTime + " (" + sleepClockC + ", " + sleepClockR + ")"); -} - -(async () => { - console.log("Logging in..."); - console.log("URL is", url + ", username is", username + ", password is", password); - global.session = await pronote.login(url, username, password); - console.log("Gathering timetable..."); - global.lessons = await session.timetable(new Date(new Date() - (86400000 * 3)), new Date(new Date().getTime() + (86400000 * 7))); - console.log("Processing..."); - - await updateSleepTime(0); - await display(-2); - console.log("-------------------"); - await display(-1); - console.log("-------------------"); - await display(0); - console.log("-------------------"); - await display(1); - console.log("-------------------"); - await display(2); - console.log("-------------------"); - await display(3); - console.log("-------------------"); - await display(4); - console.log("-------------------"); - await display(5); - console.log("-------------------"); - await display(6); - console.log("-------------------"); - await display(7); - - let json = {}; - - for (let i = -2; i < 8; i++) { - let date = new Date(new Date().getTime() + 86400000 * i).toISOString().split("T")[0]; - - json[date] = { - end: null, - firstClass: { - timestamp: null, - cloudburst: null, - raindrops: null - }, - wakeUp: { - timestamp: null, - cloudburst: null, - raindrops: null - }, - sleep: { - timestamp: null, - cloudburst: null, - raindrops: null - } - }; - - let time = await updateSleepTime(i); - - json[date].firstClass.timestamp = firstClassTime ? firstClassTime.getTime() : null; - json[date].firstClass.cloudburst = firstClassClockC ?? null; - json[date].firstClass.raindrops = firstClassClockR ?? null; - - json[date].sleep.timestamp = sleepTime ? sleepTime.getTime() : null; - json[date].sleep.cloudburst = sleepClockC ?? null; - json[date].sleep.raindrops = sleepClockR ?? null; - - json[date].wakeUp.timestamp = wakeUpTime ? wakeUpTime.getTime() : null; - json[date].wakeUp.cloudburst = wakeUpClockC ?? null; - json[date].wakeUp.raindrops = wakeUpClockR ?? null; - json[date].end = lastClassTime ?? null; - } - - console.log(json); - require('fs').writeFileSync("../../data/school.json", JSON.stringify(json)); -})()
\ No newline at end of file |