Last active
January 22, 2023 12:04
-
-
Save vigonotion/3e5ab05139e570ce46d0b3183fd567a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Name: Get Departures | |
import "@johnlindquist/kit" | |
type Station = { id: string, name: string, type: string }; | |
async function departuresDom(station: Station): Promise<string> { | |
const now = new Date(); | |
const body = { | |
"version": 47, | |
"station": station, | |
"time": { | |
"date": "heute", | |
"time": "jetzt" | |
}, | |
"maxList": 30, | |
"serviceTypes": [ | |
"BUS", | |
"ZUG", | |
"FAEHRE" | |
], | |
"useRealtime": true, | |
"maxTimeOffset": 120 | |
}; | |
let departures = (await post("https://www.hvv.de/geofox/departureList", body)).data; | |
return `<div class="pb-8 m-4"> | |
<h1>Departures at ${station.name}</h1> | |
<div class="grid" style="grid-template-columns: 48px 4fr minmax(min-content, 1fr); row-gap: 16px; column-gap: 16px;"> | |
<span class="font-bold">Line</span> | |
<span class="font-bold">Direction</span> | |
<span class="font-bold">Departure</span> | |
${departures.departures.map(d => { | |
const time = new Date(now); | |
time.setMinutes(time.getMinutes() + d.timeOffset); | |
return ` | |
<span class="w-12 flex align-center justify-start background-blue-400"> | |
<img class="self-center" src="https://cloud.geofox.de/icon/line?height=14&lineKey=${d.line.id}&fileFormat=SVG" /> | |
</span> | |
<span>${d.line.direction}</span> | |
<span>${time.toISOString().substring(11, 16)} ${d.delay > 0 ? `<span class="text-red-500">+${(d.delay ?? 0) / 60}</span>` : ''}</span> | |
`; | |
} | |
).join("")} | |
</div> | |
</div>`; | |
} | |
const station: Station = await arg("Station name", async (input) => { | |
const s = await post("https://www.hvv.de/geofox/checkName", { "version": 47, "theName": { "name": input, "type": "STATION" }, "maxList": 20, "coordinateType": "EPSG_4326" }); | |
return s?.data?.results.map(x => ({ | |
name: x.name, | |
description: x.combinedName, | |
value: x, | |
preview: async () => await departuresDom(x) | |
})) | |
}); | |
await div(await departuresDom(station)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment