Commit d964441a authored by Volker Krause's avatar Volker Krause
Browse files

Improve extraction of ÖBB station names

Those can be truncated in the RCT2 ticket data, so use what we find in the
PDF as well.
parent d6a54ef6
Pipeline #142902 passed with stages
in 1 minute and 50 seconds
/*
SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
SPDX-FileCopyrightText: 2019-2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
......@@ -11,10 +10,35 @@ function parseTicket(ticket, node) {
var res = node.result[0];
// decode 118199 vendor block
var block = ticket.block("118199");
var json = JSON.parse(block.contentText);
const block = ticket.block("118199");
const json = JSON.parse(block.contentText);
if (!res.reservationFor.trainNumber)
res.reservationFor.trainNumber = json["Z"];
return res;
}
function parsePage(pdf, node, triggerNode) {
if (triggerNode.parent.result.length > 2) // not sure this can happen
return;
// look for non-elided station names
const text = pdf.pages[triggerNode.location].text;
const legs = text.match(/VON +-> NACH.*\n.*? ([A-Z].*) +-> (.*?) .*\n.*? ([\w\*].*) +-> (.*?) /);
console.log(legs);
if (!legs) { return triggerNode.result; }
var reservations = [];
var res = triggerNode.parent.result[0];
res.reservationFor.departureStation.name = legs[1];
res.reservationFor.arrivalStation.name = legs[2];
reservations.push(res);
if (triggerNode.parent.result.length == 2) {
var res = triggerNode.parent.result[1];
res.reservationFor.departureStation.name = legs[3];
res.reservationFor.arrivalStation.name = legs[4];
reservations.push(res);
}
return reservations;
}
{
"filter": [
{
"match": "1181",
"field": "carrierId",
"mimeType": "internal/uic9183",
"scope": "Current"
}
],
"function": "parseTicket",
"script": "oebb.js",
"mimeType": "internal/uic9183"
}
[
{
"filter": [
{
"field": "carrierId",
"match": "1181",
"mimeType": "internal/uic9183",
"scope": "Current"
}
],
"function": "parseTicket",
"mimeType": "internal/uic9183",
"script": "oebb.js"
},
{
"filter": [
{
"field": "carrierId",
"match": "1181",
"mimeType": "internal/uic9183",
"scope": "Descendants"
}
],
"function": "parsePage",
"mimeType": "application/pdf",
"script": "oebb.js"
}
]
Markdown is supported
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