Auto search untis server
This commit is contained in:
@@ -24,7 +24,8 @@ services:
|
||||
- 'UNTIS_SCHOOLS=School1,School2' # Comma seperated list of schools (find in URL when logging in to untis, replace + with space)
|
||||
- 'UNTIS_USERNAMES=USERNAME1,USERNAME2' # Usernames for untis schools
|
||||
- 'UNTIS_PASSWORDS=PASSWORD1,PASSWORD2' # Passwords for untis schools
|
||||
- 'UNTIS_SERVERS=cissa.webuntis.com,neilo.webuntis.com' # Servers for untis chools
|
||||
```
|
||||
|
||||
(Nicht benötigte Umgebungsvariablen können entfernt werden)
|
||||
* `docker-compose up -d` im Verzeichnis ausführen
|
||||
|
||||
* `docker-compose up -d` im Verzeichnis ausführen
|
||||
|
||||
@@ -5,5 +5,4 @@ CALDAV_PASSWORD=PASSWORD # Password for the caldav server
|
||||
CALDAV_CALENDAR=CALENDARNAME # Calendar name from the caldav server
|
||||
UNTIS_SCHOOLS=School1,School2 # Comma seperated list of schools (find in URL when logging in to untis, replace + with space)
|
||||
UNTIS_USERNAMES=USERNAME1,USERNAME2 # Usernames for untis schools
|
||||
UNTIS_PASSWORDS=PASSWORD1,PASSWORD2 # Passwords for untis schools
|
||||
UNTIS_SERVERS=server1.webuntis.com,server2.webuntis.com # Servers for untis chools
|
||||
UNTIS_PASSWORDS=PASSWORD1,PASSWORD2 # Passwords for untis schools
|
||||
@@ -58,24 +58,48 @@ function getCalendarEntries(weekDate) {
|
||||
return result;
|
||||
}
|
||||
|
||||
async function getUntis(weekDate) {
|
||||
let untisSchools = [];
|
||||
let untisUsernames = [];
|
||||
let untisPasswords = [];
|
||||
let untisServers = [];
|
||||
async function getUntisServer(school) {
|
||||
const searchSchool = await fetch("https://mobile.webuntis.com/ms/schoolquery2", {
|
||||
"method": "POST",
|
||||
"body": JSON.stringify({
|
||||
"id": "wu_schulsuche-" + (new Date()).getTime(),
|
||||
"method": "searchSchool",
|
||||
"params": [
|
||||
{
|
||||
"search": school
|
||||
}
|
||||
],
|
||||
"jsonrpc": "2.0"
|
||||
})
|
||||
});
|
||||
|
||||
let optionsSuccess = true;
|
||||
try {
|
||||
untisSchools = process.env.UNTIS_SCHOOLS.split(",");
|
||||
untisUsernames = process.env.UNTIS_USERNAMES.split(",");
|
||||
untisPasswords = process.env.UNTIS_PASSWORDS.split(",");
|
||||
untisServers = process.env.UNTIS_SERVERS.split(",");
|
||||
} catch (error) {
|
||||
optionsSuccess = false;
|
||||
}
|
||||
const searchSchoolJson = await searchSchool.json();
|
||||
|
||||
if (!optionsSuccess) {
|
||||
return "Keine Untis-Optionen gefunden";
|
||||
return searchSchoolJson.result.schools[0].server;
|
||||
}
|
||||
|
||||
const untisServers = [];
|
||||
let untisSchools = [];
|
||||
let untisUsernames = [];
|
||||
let untisPasswords = [];
|
||||
async function getUntis(weekDate) {
|
||||
if (untisServers.length == 0) {
|
||||
let optionsSuccess = true;
|
||||
try {
|
||||
untisSchools = process.env.UNTIS_SCHOOLS.split(",");
|
||||
untisUsernames = process.env.UNTIS_USERNAMES.split(",");
|
||||
untisPasswords = process.env.UNTIS_PASSWORDS.split(",");
|
||||
} catch (error) {
|
||||
optionsSuccess = false;
|
||||
}
|
||||
|
||||
if (!optionsSuccess) {
|
||||
return "Keine Untis-Optionen gefunden";
|
||||
}
|
||||
|
||||
for (school of untisSchools) {
|
||||
untisServers.push(await getUntisServer(school));
|
||||
}
|
||||
}
|
||||
|
||||
let teachingContent = "";
|
||||
@@ -182,7 +206,7 @@ app.get('/show', (req, res) => {
|
||||
if (process.env.CALDAV_URL == undefined || process.env.CALDAV_USER == undefined || process.env.CALDAV_PASSWORD == undefined || process.env.CALDAV_CALENDAR == undefined) {
|
||||
showCalendar = false;
|
||||
}
|
||||
if (process.env.UNTIS_SCHOOLS == undefined || process.env.UNTIS_USERNAMES == undefined || process.env.UNTIS_PASSWORDS == undefined || process.env.UNTIS_SERVERS == undefined) {
|
||||
if (process.env.UNTIS_SCHOOLS == undefined || process.env.UNTIS_USERNAMES == undefined || process.env.UNTIS_PASSWORDS == undefined) {
|
||||
showUntis = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user