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

0001 /*
0002    SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003    SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 function parseTicket(content, node, triggerNode) {
0007     const text = content.text;
0008     const ref = text.match(/(?:BOOKING REFERENCE|RÉSERVATION) +([A-Z0-9]{6})\n/)[1];
0009 
0010     // not really a valid IATA BCBP, but we can use parts of it at least
0011     const bcbp = triggerNode.content.substr(0, 22).match(/^M(\d)([^\/]+)\/(.*) */);
0012     var person = JsonLd.newObject("Person");
0013     person.familyName = bcbp[2];
0014     person.givenName = bcbp[3];
0015 
0016     var reservations = [];
0017     var idx = 0;
0018     while (true) {
0019         const leg = text.substr(idx).match(/(\d\d:\d\d) *(\d\d:\d\d)(?:.*)?\n *(\d\d[A-Z]{3}) +(.*?)  +(.*?)  +([A-Z0-9]{2}\d{4}).*\n *([A-Z]{3})  +([A-Z]{3}).*\n.*?(?:  +Siège\/Seat : ([0-9A-Z]+))?\n(?:.*\n)?.*(?:Flight operated by|Vol effectué par) (.*)\n/);
0020         if (!leg) {
0021             break;
0022         }
0023         idx += leg.index + leg[0].length;
0024 
0025         var res;
0026         if (leg[10] == 'SNCF') {
0027             res = JsonLd.newTrainReservation();
0028             res.reservationFor.departureStation.name = leg[4];
0029             res.reservationFor.departureStation.identifier = 'iata:' + leg[7];
0030             res.reservationFor.arrivalStation.name = leg[5];
0031             res.reservationFor.arrivalStation.identifier = 'iata:' + leg[8];
0032             res.reservationFor.trainNumber = leg[6];
0033             res.reservationFor.provider.name = leg[10];
0034         } else {
0035             res = JsonLd.newFlightReservation();
0036             res.reservationFor.departureAirport.name = leg[4];
0037             res.reservationFor.departureAirport.iataCode = leg[7];
0038             res.reservationFor.arrivalAirport.name = leg[5];
0039             res.reservationFor.arrivalAirport.iataCode = leg[8];
0040             res.reservationFor.flightNumber = leg[6];
0041             res.reservationFor.airline.name = leg[10];
0042             res.airplaneSeat = leg[9];
0043         }
0044 
0045         res.reservationFor.departureTime = JsonLd.toDateTime(leg[1] + ' ' + leg[3], "hh:mm ddMMM", "en");
0046         res.reservationFor.arrivalTime = JsonLd.toDateTime(leg[2] + ' ' + leg[3], "hh:mm ddMMM", "en");
0047         res.reservationNumber = ref;
0048         res.underName = person;
0049         res.reservedTicket.ticketToken = "azteccode:" + triggerNode.content;
0050         reservations.push(res);
0051     }
0052 
0053     return reservations;
0054 }