35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
import axios from "axios";
|
|
const baseUrl = "https://mobileapi.dsbcontrol.de";
|
|
|
|
export async function getAuthtoken(username, password) {
|
|
const response = await axios.get(
|
|
`${baseUrl}/authid?user=${username}&password=${password}&bundleid&appversion&osversion&pushid`
|
|
);
|
|
if (response.data == "") throw "Wrong username or password";
|
|
return response.data;
|
|
}
|
|
|
|
export async function getTimetables(authtoken) {
|
|
const response = await axios.get(
|
|
`${baseUrl}/dsbtimetables?authid=${authtoken}`
|
|
);
|
|
const timetables = response.data;
|
|
|
|
const urls = [];
|
|
timetables.forEach((timetable) => {
|
|
const rawTimestamp = timetable.Date;
|
|
// Convert the timestamp to the correct
|
|
// format so new Date() accepts it
|
|
const date = rawTimestamp.split(" ")[0].split(".").reverse().join("-");
|
|
const time = rawTimestamp.split(" ")[1];
|
|
const timestamp = date + " " + time;
|
|
urls.push({
|
|
title: timetable.Title,
|
|
url: timetable.Childs[0].Detail,
|
|
updatedAt: new Date(timestamp),
|
|
});
|
|
});
|
|
|
|
return urls;
|
|
}
|