diff --git a/src/extractors/extractors.qrc b/src/extractors/extractors.qrc index 4e4453d..b78fc8f 100644 --- a/src/extractors/extractors.qrc +++ b/src/extractors/extractors.qrc @@ -1,97 +1,99 @@ acprail.json acprail.js aerlingus.json aerlingus.js airbaltic.json airbaltic.js aircoach-ie.json aircoach-ie.js amadeus.json amadeus.js americanairlines.json americanairlines.js aohostels.json aohostels.js availpro.json availpro.js booking.json booking.js brusselsairlines.json brusselsairlines.js brusselsairlines-receipt.js chaos-communication-congress.json chaos-communication-congress.js czechrailways.json czechrailways.js deutschebahn.json deutschebahn.js dinnerbooking.json dinnerbooking.js easyairportparking.json easyairportparking-pkpass.js easyjet.json easyjet.js eurowings.json eurowings.js eurowings-pkpass.js fcmtravel.json fcmtravel.js flixbus.json flixbus.js hertz.js hertz.json iberia.json iberia.js indigo.json indigo.js irctc.json irctc.js kintetsu.json kintetsu.js klm.json klm.js koleje-malopolskie.json koleje-malopolskie.js korail.json korail.js lufthansa.json lufthansa-pkpass.js nationalexpress.json nationalexpress.js nh-hotels.json nh-hotels.js norwegian.json norwegian.js np4.json np4.js oebb.json oebb.js regiojet.json regiojet.js renfe.json renfe.js sas.json sas-boardingpass.js sas-receipt.js simplebooking.json simplebooking.js sncf.json sncf.js stansted-express.json stansted-express.js swiss.json swiss.js thalys.json thalys.js travelport-galileo.json travelport-galileo.js trenitalia.json trenitalia.js vgn.json vgn.js + vr.fi.json + vr.fi.js vueling.json vueling.js diff --git a/src/extractors/vr.fi.js b/src/extractors/vr.fi.js new file mode 100644 index 0000000..d493071 --- /dev/null +++ b/src/extractors/vr.fi.js @@ -0,0 +1,49 @@ +/* + Copyright (C) 2020 Volker Krause + + This program 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 program 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 General Public License + along with this program. If not, see . +*/ + +// see https://community.kde.org/KDE_PIM/KItinerary/vr.fi_Barcode +function parseTicket(pdf) { + var res = JsonLd.newTrainReservation(); + var bitarray = Barcode.toBitArray(Context.barcode); + + var trainNum = bitarray.readNumberMSB(22 * 8, 14) + ""; + if (trainNum == 0) + return null; // TODO this misses bus legs! + + var text = pdf.pages[Context.pdfPageNumber].text; + var trip = text.match("(.*) - (.*)\n.*(\\d{4}).*?(\\d{2}:\\d{2}).*?(\\d{2}:\\d{2})\n(.*?" + trainNum + ")"); + res.reservationFor.trainNumber = trip[6]; + + var departureDay = bitarray.readNumberMSB(4 * 8 + 7, 9) - 1; + var day = new Date(0); + day.setYear(trip[3]); + day.setTime(day.getTime() + departureDay * 24 * 60 * 60 * 1000); + res.reservationFor.departureTime = JsonLd.toDateTime(day.getFullYear() + '-' + (day.getMonth() + 1) + '-' + day.getDate() + '-' + trip[4], "yyyy-M-d-hh:mm", "en"); + res.reservationFor.arrivalTime = JsonLd.toDateTime(day.getFullYear() + '-' + (day.getMonth() + 1) + '-' + day.getDate() + '-' + trip[5], "yyyy-M-d-hh:mm", "en"); + + var coachNumber = bitarray.readNumberMSB(30 * 8, 6); + if (coachNumber > 0) { + res.reservedTicket.ticketedSeat.seatSection = coachNumber + ""; + res.reservedTicket.ticketedSeat.seatNumber = bitarray.readNumberMSB(30 * 8 + 6, 7) + ""; + } + + res.reservationFor.departureStation.name = trip[1]; + res.reservationFor.arrivalStation.name = trip[2]; + + res.reservedTicket.ticketToken = "aztectbin:" + Barcode.toBase64(Context.barcode); + return res; +} diff --git a/src/extractors/vr.fi.json b/src/extractors/vr.fi.json new file mode 100644 index 0000000..3bd6de5 --- /dev/null +++ b/src/extractors/vr.fi.json @@ -0,0 +1,11 @@ +{ + "filter": [ + { + "match": "^\\x{10}", + "type": "Barcode" + } + ], + "function": "parseTicket", + "script": "vr.fi.js", + "type": "Pdf" +}