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

0001 /*
0002    SPDX-FileCopyrightText: 2022 Kai Uwe Broulik <kde@broulik.de>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 function main(pass, node)
0008 {
0009     let res = node.result[0];
0010 
0011     const departureTime = JsonLd.toDateTime(pass.field["departuretime"].value, "hh:mm", "en");
0012     if (!isNaN(departureTime.getTime())) {
0013         res.reservationFor.departureTime = departureTime;
0014     }
0015 
0016     const arrivalTime = JsonLd.toDateTime(pass.field["arrivaltime"].value, "hh:mm", "en");
0017     if (!isNaN(arrivalTime.getTime())) {
0018         res.reservationFor.arrivalTime = arrivalTime;
0019     }
0020 
0021     const modifyField = pass.field["modify_checkin"];
0022     if (modifyField) {
0023         res.potentialAction = JsonLd.newObject("UpdateAction");
0024         res.potentialAction.url = modifyField.value;
0025     }
0026 
0027     return res;
0028 }
0029 
0030 function parseHtmlConfirmation(html)
0031 {
0032     let reservations = [];
0033     const pnr = html.root.eval('//div[starts-with(@class, "bookCode")]')[0].recursiveContent;
0034 
0035     const flights = html.root.eval('//table[@class="flightBoundLineRecap" or @class="detailContainer"]');
0036     let date = "";
0037     for (flight of flights) {
0038         if (flight.attribute('class') == 'flightBoundLineRecap') {
0039             date = flight.eval('.//strong')[0].content.match(/\S+ (.*)/)[1];
0040             continue;
0041         }
0042         let res = JsonLd.newFlightReservation();
0043         res.reservationNumber = pnr;
0044 
0045         const origin = flight.eval('.//*[@class="originDateAirport"]')[0].recursiveContent.match(/(\d\d:\d\d)\s+(.*)/);
0046         res.reservationFor.departureAirport.name = origin[2];
0047         res.reservationFor.departureTime = JsonLd.toDateTime(date + ' ' + origin[1], 'dd.MMM hh:mm', ['en', 'de']);
0048         const destination = flight.eval('.//*[@class="destinationDateAirport"]')[0].recursiveContent.match(/(\d\d:\d\d)\s+(.*)/);
0049         res.reservationFor.arrivalAirport.name = destination[2];
0050         res.reservationFor.arrivalTime = JsonLd.toDateTime(date + ' ' + destination[1], 'dd.MMM hh:mm', ['en', 'de']);
0051         const airline = flight.eval('.//div[@class="aircraftAndAirline"]/div')[0].content.match(/([A-Z0-9]{2})(\d{1,4})/);
0052         res.reservationFor.airline.iataCode = airline[1];
0053         res.reservationFor.flightNumber = airline[2];
0054 
0055         reservations.push(res);
0056     }
0057 
0058     return reservations;
0059 }