Commit 5d199c8d authored by Volker Krause's avatar Volker Krause
Browse files

Add extractor for Koleje Małopolskie

Uses a JSON structure with almost all relevant information in a QR code.
parent eb9afd6b
......@@ -34,6 +34,8 @@
<file>iberia.js</file>
<file>klm.json</file>
<file>klm.js</file>
<file>koleje-malopolskie.json</file>
<file>koleje-malopolskie.js</file>
<file>korail.json</file>
<file>korail.js</file>
<file>lufthansa.json</file>
......
/*
Copyright (c) 2019 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
function parsePdf(pdf) {
var reservations = new Array();
for (var i = 0; i < pdf.pageCount; ++i) {
var page = pdf.pages[i];
var images = page.images;
for (var j = 0; j < images.length; ++j) {
if (Math.abs(images[j].width - images[j].height) > 10) // almost square
continue;
var barcode = Barcode.decodeQR(images[j]);
var obj = JSON.parse(barcode);
if (!obj)
continue;
var res = JsonLd.newObject("TrainReservation");
res.reservedTicket = JsonLd.newObject("Ticket");
res.reservationFor = JsonLd.newObject("TrainTrip");
res.reservationFor.departureStation = JsonLd.newObject("TrainStation");
res.reservationFor.arrivalStation = JsonLd.newObject("TrainStation");
res.underName = JsonLd.newObject("Person");
res.underName.givenName = obj.name;
res.underName.familyName = obj.surname
res.reservationNumber = obj.idDocValue;
res.reservationFor.trainNumber = obj.nrKursu;
res.reservationFor.departureStation.name = obj.fromStop;
res.reservationFor.arrivalStation.name = obj.toStop;
var depDate = new Date();
depDate.setTime(obj.goDate);
res.reservationFor.departureTime = depDate;
reservations.push(res);
}
}
return reservations;
}
[
{
"type": "pdf",
"filter": [
{ "type": "Barcode", "match": "docType.:.INTERNATIONAL_ID" }
],
"script": "koleje-malopolskie.js",
"function": "parsePdf"
}
]
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