File indexing completed on 2024-12-29 04:51:04

0001 /*
0002    SPDX-FileCopyrightText: 2023 Luca Weiss <luca@z3ntu.xyz>
0003    SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 function parsePdfTicket(pdf, node, triggerNode) {
0007     // Parse the reservation data from the text in the pdf.
0008     // Note that in the English version most fields end with a colon, the Greek
0009     // version doesn't - as of 2023-07-04.
0010     const text = pdf.pages[triggerNode.location].text;
0011     let res = JsonLd.newBusReservation();
0012 
0013     // Potentially the "K12345 / E98765" number below the QR code would be a
0014     // better reservationNumber, but it's not clear enough for now.
0015     res.reservationNumber = triggerNode.content;
0016     res.reservedTicket.ticketToken = 'qrCode:' + triggerNode.content;
0017 
0018     const route = text.match(/(?:Route|Διαδρομή)[ ]+(.*)/);
0019     res.reservationFor.busNumber = route[1];
0020 
0021     const depTime = text.match(/(?:Boarding time:|Ώρα αναχώρησης)[ ]+(\d{4}-\d{2}-\d{2} \d{2}:\d{2})/);
0022     res.reservationFor.departureTime = JsonLd.toDateTime(depTime[1], 'yyyy-MM-dd hh:mm', 'gr');
0023 
0024     const dep = text.match(/(?:Boarding:|Επιβίβαση)[ ]+(.*)/);
0025     console.log(dep[1]);
0026     res.reservationFor.departureBusStop.name = dep[1];
0027 
0028     const arr = text.match(/(?:Disembark:|Αποβίβαση)[ ]+(.*)/);
0029     res.reservationFor.arrivalBusStop.name = arr[1];
0030 
0031     const name = text.match(/(?:Passenger name:|Όνομα επιβάτη)[ ]+(.*)/);
0032     res.underName.name = name[1];
0033 
0034     const seat = text.match(/(?:Seat number:|Θέση)[ ]+(\d+)/);
0035     res.reservedTicket.ticketedSeat.seatNumber = seat[1];
0036 
0037     const price = text.match(/(?:Price:|Τιμή)[ ]+(\d+\.\d{2})€/);
0038     res.totalPrice = price[1];
0039     res.priceCurrency = 'EUR';
0040 
0041     return res;
0042 }