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

0001 /*
0002     SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 function extractBookingConfirmation(html) {
0007     const text = html.root.recursiveContent;
0008     const bookingNo = text.match(/Booking no.\n([A-Z0-9]{6})/)[1];
0009     let reservations = [];
0010     let idx = 0;
0011     while (true) {
0012         const flight = text.substr(idx).match(/Flight \d+\n +\S+, (.*)\n(?:.*\n)+?(\d\d: *\d\d)\n(.*) \(([A-Z]{3})\) *\n(\d\d:\d\d)\n *(\S.*) \(([A-Z]{3})\)\n(?:(.*)\n)?([A-Z0-9]{2}) +(\d{1,4})\n/);
0013         if (!flight)
0014             break;
0015         idx += flight.index + flight[0].length;
0016 
0017         let res = JsonLd.newFlightReservation();
0018         res.reservationFor.departureTime = JsonLd.toDateTime(flight[1] + ' ' + flight[2], 'dd MMM yyyy hh: mm', 'en');
0019         res.reservationFor.departureAirport.name = flight[3];
0020         res.reservationFor.departureAirport.iataCode = flight[4];
0021         // TODO departure terminal?
0022         res.reservationFor.arrivalTime = JsonLd.toDateTime(flight[1] + ' ' + flight[5], 'dd MMM yyyy hh:mm', 'en');
0023         res.reservationFor.arrivalAirport.name = flight[6];
0024         res.reservationFor.arrivalAirport.iataCode = flight[7];
0025         res.reservationFor.arrivalTerminal = flight[8];
0026         res.reservationFor.airline.iataCode = flight[9];
0027         res.reservationFor.flightNumber = flight[10];
0028         res.reservationNumber = bookingNo;
0029         reservations.push(res);
0030     }
0031 
0032     // TODO passenger names
0033 
0034     return reservations;
0035 }