✨ Add parser scripts
This commit is contained in:
32
server/parser/dsbmobile.js
Normal file
32
server/parser/dsbmobile.js
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user