Commit 6619f5ae authored by Volker Krause's avatar Volker Krause
Browse files

Make the VIA Rail extractor work both with a full PDF or just the barcode

Also, retrieve full station names and arrival times from the PDF.
parent e20b9822
Pipeline #106975 passed with stage
in 4 minutes and 3 seconds
......@@ -4,7 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function parseBoardingPass(pdf, node, triggerNode) {
function parseBarcode(barcode) {
// barcode content
// 13x FTR number
// 29x traveler family name
......@@ -16,24 +16,39 @@ function parseBoardingPass(pdf, node, triggerNode) {
// 4x train number
// 8x departure date yyyyMMdd
// 4x departure time hhmm
// 22x given name
// 20x given name
// 2x stuff, often empty
// 5x stuff, possibly containing Adult/Child/etc info
// 6x confirmation number
// 12x purchase date/time as yyyyMMddhhmm
// 6x stuff, presumably class being part of this
var barcode = triggerNode.content;
var res = JsonLd.newTrainReservation();
res.reservationFor.provider = barcode.substr(58, 3);
res.reservationFor.trainNumber = barcode.substr(61, 4).trim();
res.reservationFor.departureTime = JsonLd.toDateTime(barcode.substr(65, 12), "yyyyMMddhhmm", "en");
res.reservationFor.departureStation.identifier = 'via:' + barcode.substr(50, 4);
res.reservationFor.departureStation.name = barcode.substr(50, 4);
res.reservationFor.arrivalStation.identifier = 'via:' + barcode.substr(54, 4);
res.reservationFor.arrivalStation.name = barcode.substr(54, 4);
res.reservedTicket.ticketedSeat.seatSection = barcode.substr(42, 2).trim();
res.reservedTicket.ticketedSeat.seatNumber = barcode.substr(44, 6).trim();
res.reservedTicket.ticketToken = "azteccode:" + barcode;
res.underName.familyName = barcode.substr(13, 29).trim();
res.underName.givenName = barcode.substr(77, 22).trim();
res.underName.givenName = barcode.substr(77, 20).trim();
res.reservationNumber = barcode.substr(104, 6);
return res;
}
function parseBoardingPass(pdf, node, triggerNode) {
var res = node.result[0];
const text = pdf.pages[triggerNode.location].text;
const stationNames = text.match(/FTR\s*:\s*\d+\n(.*) +(.*)\n/);
res.reservationFor.departureStation.name = stationNames[1];
res.reservationFor.arrivalStation.name = stationNames[2];
const arrivalDate = text.match(/Date\s*:.*Date\s*:\s*\w+\.\s*(.*)\n/);
const arrivalTime = text.match(/Arrival\s*:\s*(.*)\n/);
console.log(arrivalDate[1] + ' ' + arrivalTime[1]);
res.reservationFor.arrivalTime = JsonLd.toDateTime(arrivalDate[1] + ' ' + arrivalTime[1], 'MMM d, yyyy HH:mm AP', 'en');
return res;
}
{
[{
"filter": [
{
"match": "^\\d{13}.{37}[A-Z]{8}VIA",
......@@ -7,6 +7,18 @@
}
],
"function": "parseBoardingPass",
"script": "viarail.js",
"mimeType": "application/pdf"
}
"mimeType": "application/pdf",
"script": "viarail.js"
},
{
"filter": [
{
"match": "^\\d{13}.{37}[A-Z]{8}VIA",
"mimeType": "text/plain",
"scope": "Current"
}
],
"function": "parseBarcode",
"mimeType": "text/plain",
"script": "viarail.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