1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { fetch } from "https://esm.town/v/std/fetch";
export async function getReiseauskunftTrain(url) {
const { DOMParser } = await import(
"https://deno.land/x/deno_dom/deno-dom-wasm.ts"
);
function cleanTime(time) {
const cleaned = time
.trim()
.replace("Ankunft\nan ", "")
.replace("Abfahrt\nab ", "");
return cleaned === "" ? undefined : cleaned;
}
return fetch(url)
.then((res) => res.text())
.then((html) => new DOMParser().parseFromString(html, "text/html"))
.then((document) => {
return {
route: [
...document.querySelectorAll(
"#trainroute > .trainrow_1, .trainrow_2"
),
].map((row) => {
return {
station: {
code: $hanbzu.extractReiseauskunftDbStationCodeFromUrl(
row.querySelector(".station > a").getAttribute("href")
),
name: row.querySelector(".station > a").textContent.trim(),
},
arr: cleanTime(row.querySelector(".arrival").textContent),
dep: cleanTime(row.querySelector(".departure").textContent),
};
}),
remarks: document
.querySelector(".tqRemarks")
?.textContent?.trim()
?.replace("Hinweise\n", ""),
};
});
}