Commit 54a0be21 authored by Volker Krause's avatar Volker Krause
Browse files

Extract full itenerary from Deutsche Bahn ical events

Also, make this work with the iCal events downloadable from their journey
query site prior to booking. This for once allows to generate arbitrary
non-personalized test cases.
parent c736c837
Pipeline #209160 passed with stage
in 6 minutes and 55 seconds
BEGIN:VCALENDAR
VERSION:2.0
X-LOTUS-CHARSET:UTF-8
PRODID:http://www.hacon.de
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID:Europe/Berlin
X-LIC-LOCATION:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
UID:20220726102600@hafas
CLASS:PUBLIC
SUMMARY:Frankfurt(Main)Hbf -> Paris Nord
DTSTART;TZID=Europe/Berlin:20220726T102600
DTEND;TZID=Europe/Berlin:20220726T160500
DTSTAMP:20220726T094600Z
DESCRIPTION:Reise: Frankfurt(Main)Hbf nach Paris Nord\nDatum: 26.07.22\n-\nab 10:26 Frankfurt(Main)Hbf - Gleis 19 (ICE 16)\nan 11:33 Köln Hbf - Gleis 6\n\nab 12:42 Köln Hbf - Gleis 8 D-G (THA 9448)\nan 16:05 Paris Nord \n-\nDauer: 5:39 \, Umsteigevorgänge 1\n\nAlle Angaben ohne Gewähr. Fahrplanänderungen vorbehalten. Bitte prüfen Sie kurz vor der Reise den aktuellen Fahrplan unter: www.bahn.de\n
END:VEVENT
END:VCALENDAR
[
{
"@context": "http://schema.org",
"@type": "TrainReservation",
"reservationFor": {
"@type": "TrainTrip",
"arrivalPlatform": "6",
"arrivalStation": {
"@type": "TrainStation",
"name": "Köln Hbf"
},
"arrivalTime": "2022-07-26T11:33:00",
"departureDay": "2022-07-26",
"departurePlatform": "19",
"departureStation": {
"@type": "TrainStation",
"name": "Frankfurt(Main)Hbf"
},
"departureTime": {
"@type": "QDateTime",
"@value": "2022-07-26T10:26:00+02:00",
"timezone": "Europe/Berlin"
},
"trainName": "ICE 16"
},
"reservationStatus": "http://schema.org/ReservationConfirmed"
},
{
"@context": "http://schema.org",
"@type": "TrainReservation",
"reservationFor": {
"@type": "TrainTrip",
"arrivalStation": {
"@type": "TrainStation",
"name": "Paris Nord"
},
"arrivalTime": {
"@type": "QDateTime",
"@value": "2022-07-26T16:05:00+02:00",
"timezone": "Europe/Berlin"
},
"departureDay": "2022-07-26",
"departurePlatform": "8 D-G",
"departureStation": {
"@type": "TrainStation",
"name": "Köln Hbf"
},
"departureTime": "2022-07-26T12:42:00",
"trainName": "THA 9448"
},
"reservationStatus": "http://schema.org/ReservationConfirmed"
}
]
......@@ -324,5 +324,35 @@ function parseEvent(event) {
res.reservationFor.departureTime = JsonLd.readQDateTime(event, 'dtStart');
res.reservationFor.arrivalStation.name = names[2];
res.reservationFor.arrivalTime = JsonLd.readQDateTime(event, 'dtEnd');
// search for more details in the description
let reservations = [];
let idx = 0;
while (true) {
const trip = event.description.substr(idx).match(/ab (\d{2}:\d{2}) (.*?)(?:\n|- Gleis (.*) \((.*)\)\n)an (\d{2}:\d{2}) (.*?)(?:\n| - Gleis (.*)\n)/);
if (!trip) {
break;
}
idx += trip.index + trip[0].length;
let res = JsonLd.newTrainReservation();
const date = JsonLd.readQDateTime(event, 'dtStart')['@value'].substr(0, 10);
res.reservationFor.departureStation.name = trip[2];
res.reservationFor.departureTime = JsonLd.toDateTime(date + trip[1], 'yyyy-MM-ddhh:mm', 'de');
res.reservationFor.departurePlatform = trip[3];
res.reservationFor.trainName = trip[4];
res.reservationFor.arrivalStation.name = trip[6];
res.reservationFor.arrivalTime = JsonLd.toDateTime(date + trip[5], 'yyyy-MM-ddhh:mm', 'de');
res.reservationFor.arrivalPlatform = trip[7];
reservations.push(res);
}
// recover full timezones for the begin/end
if (reservations.length > 0) {
reservations[0].reservationFor.departureTime = res.reservationFor.departureTime;
reservations[reservations.length - 1].reservationFor.arrivalTime = res.reservationFor.arrivalTime;
return reservations;
}
return res;
}
......@@ -83,6 +83,12 @@
"match": "^bahn\\d{14}$",
"mimeType": "internal/event",
"scope": "Current"
},
{
"field": "uid",
"match": "^\\d{14}@hafas$",
"mimeType": "internal/event",
"scope": "Current"
}
],
"function": "parseEvent",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment