Commit 3c6df987 authored by Volker Krause's avatar Volker Krause
Browse files

Support extracting Renfe pkpass files

Also fix extraction of newer Renfe PDF tickets.

BUG: 451974
FIXED-IN: 22.04.0
parent 67373821
Pipeline #156608 passed with stages
in 4 minutes and 16 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
*/
function parsePdf(pdf, node, triggerNode)
function parseBarcode(barcode)
{
if (!triggerNode.content)
return;
// barcode content:
// 13x ticket number
// 5x Renfe departure station id
......@@ -22,25 +19,59 @@ function parsePdf(pdf, node, triggerNode)
// ".." (optional)
// 5x "CombinadoCercanias" (optional)
var barcode = triggerNode.content;
if (barcode.length > 56)
return null;
var res = JsonLd.newTrainReservation();
res.reservedTicket.ticketToken = "dataMatrix:" + barcode;
res.reservedTicket.ticketToken = "qrCode:" + barcode;
res.reservationFor.trainNumber = barcode.substr(29, 5);
res.reservedTicket.ticketedSeat.seatSection = barcode.substr(34, 3);
res.reservedTicket.ticketedSeat.seatNumber = barcode.substr(37, 3);
res.reservationNumber = barcode.substr(43);
res.reservationNumber = barcode.substr(43, 6);
res.reservationFor.departureStation.identifier = "uic:71" + barcode.substr(13, 5);
res.reservationFor.arrivalStation.identifier = "uic:71" + barcode.substr(18, 5);
res.reservationFor.departureDay = JsonLd.toDateTime(barcode.substr(23, 6), 'ddMMyy', 'es');
return res;
}
function parsePdf(pdf, node, triggerNode)
{
if (!triggerNode.content)
return;
var res = parseBarcode(triggerNode.content.trim());
var text = pdf.pages[triggerNode.location].text;
var dep = text.match(/Salida +(.*?) {2,}([\d\/]+) +(\d\d:\d\d)/);
var dep = text.match(/(?:Salida|Origen:) +(.*?) {2,}([\d\/]+) +(\d\d:\d\d)/);
res.reservationFor.departureStation.name = dep[1];
res.reservationFor.departureStation.identifier = "uic:71" + barcode.substr(13, 5);
res.reservationFor.departureTime = JsonLd.toDateTime(dep[2] + dep[3], "dd/MM/yyyyhh:mm", "es");
var arr = text.match(/Llegada\s+(.*?) {2,}([\d\/]+) +(\d\d:\d\d)\n *(\S+) /);
var arr = text.match(/(?:Llegada|Destino:)\s+(.*?) {2,}([\d\/]+) +(\d\d:\d\d)\n *(\S+) /);
res.reservationFor.arrivalStation.name = arr[1];
res.reservationFor.arrivalStation.identifier = "uic:71" + barcode.substr(18, 5);
res.reservationFor.arrivalTime = JsonLd.toDateTime(arr[2] + arr[3], "dd/MM/yyyyhh:mm", "es");
res.reservationFor.trainName = arr[4];
return res;
}
function parsePkPass(content)
{
var res = parseBarcode(content.barcodes[0].message);
res.reservationFor.provider.name = content.organizationName;
const day = content.field['destinofecha'].value;
res.reservationFor.departureTime = JsonLd.toDateTime(day + ' ' + content.field['boardingTime'].value, 'dd/MM/yyyy hh:mm', 'es');
res.reservationFor.departureStation.name = content.field['boardingTime'].label;
res.reservationFor.arrivalTime = JsonLd.toDateTime(day + ' ' + content.field['destino'].value, 'dd/MM/yyyy hh:mm', 'es');
res.reservationFor.arrivalStation.name = content.field['destino'].label;
res.underName.name = content.field['nombrepasajero'].value;
if (content.field['documentos']) {
const program = content.field['documentos'].value.match(/(.*) +: +(.*)/);
if (program) {
res.programMembershipUsed.name = program[1];
res.programMembershipUsed.membershipNumber = program[2];
}
}
return res;
}
{
[{
"filter": [
{
"match": "^\\d{13}.*\\S{6}(\\.\\.\\S{5}| +)?$",
......@@ -9,4 +9,16 @@
"function": "parsePdf",
"script": "renfe.js",
"mimeType": "application/pdf"
}
}, {
"filter": [
{
"field": "passTypeIdentifier",
"match": "pass.com.renfe-RenfeTicket",
"mimeType": "application/vnd.apple.pkpass",
"scope": "Current"
}
],
"function": "parsePkPass",
"mimeType": "application/vnd.apple.pkpass",
"script": "renfe.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