Add parser scripts

This commit is contained in:
2022-05-02 00:47:04 +02:00
parent 69c601ebe8
commit 9bd8132119
2 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,32 @@
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;
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;
}