chore: add package.json with initial dependencies and project metadata
This commit is contained in:
39
index.js
Normal file
39
index.js
Normal file
@@ -0,0 +1,39 @@
|
||||
require('dotenv').config()
|
||||
const express = require('express')
|
||||
const luxon = require('luxon');
|
||||
const { WebUntis } = require('webuntis');
|
||||
|
||||
const app = express()
|
||||
const port = process.env.PORT || 3000
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send('server is running')
|
||||
})
|
||||
|
||||
app.get('/timetable', async (req, res) => {
|
||||
const untis = new WebUntis(process.env.WEBUNTIS_SCHOOL, process.env.WEBUNTIS_USER, process.env.WEBUNTIS_PASS, process.env.WEBUNTIS_URL);
|
||||
try {
|
||||
await untis.login();
|
||||
// Start und Ende der aktuellen Woche bestimmen
|
||||
|
||||
const now = luxon.DateTime.local();
|
||||
const startOfWeek = now.startOf('week').toJSDate(); // Montag
|
||||
const endOfWeek = now.endOf('week').plus({ days: 7*4*4 }).toJSDate(); // Sonntag
|
||||
|
||||
// Stundenplan für diese Woche abrufen
|
||||
const timetable = await untis.getOwnTimetableForRange(startOfWeek, endOfWeek);
|
||||
|
||||
await untis.logout();
|
||||
res.json({ status: 'success', data: timetable });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.statusCode = 500;
|
||||
res.json({ status: 'error', message: error.message || error.toString() });
|
||||
}
|
||||
})
|
||||
|
||||
console.log(process.env)
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`)
|
||||
})
|
||||
Reference in New Issue
Block a user