File indexing completed on 2024-12-29 04:51:06
0001 /* 0002 SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 function parseHtmlBooking(doc) { 0008 var reservations = new Array(); 0009 0010 var bookingRef = doc.eval("//td[@class=\"vuelo_confirmado_header\"]")[0].firstChild.content; 0011 if (!bookingRef) 0012 return null; 0013 0014 var lang = doc.eval('//a[@class="copyright-text"]')[0].attribute("href").match(/\/([a-z]{2})$/)[1]; 0015 0016 var elems = doc.eval("//td[@class=\"vuelo_confirmado_card__subheader\"]"); 0017 for (var i = 0; i < elems.length; ++i) { 0018 var elem = elems[i]; 0019 var detailsRoot = elem.parent.nextSibling; 0020 0021 var res = JsonLd.newFlightReservation(); 0022 res.reservationNumber = bookingRef; 0023 0024 var airportName = detailsRoot.eval(".//td[@class=\"vuelo_confirmado_card_details--city salida\"]")[0]; 0025 var iataCode = detailsRoot.eval(".//td[@class=\"vuelo_confirmado_card_details--iata\"]")[0]; 0026 res.reservationFor.departureAirport.iataCode = iataCode.content; 0027 res.reservationFor.departureAirport.name = airportName.content; 0028 res.reservationFor.arrivalAirport.iataCode = iataCode.nextSibling.content; 0029 res.reservationFor.arrivalAirport.name = airportName.nextSibling.content; 0030 0031 var time = detailsRoot.eval(".//td[@class=\"vuelo_confirmado_card_details--time\"]")[0]; 0032 res.reservationFor.departureTime = JsonLd.toDateTime(elem.content + ' ' + time.content.replace('h', ''), "dddd, dd MMMM yyyy HH:mm", lang); 0033 res.reservationFor.arrivalTime = JsonLd.toDateTime(elem.content + ' ' + time.nextSibling.content.replace('h', ''), "dddd, dd MMMM yyyy HH:mm", lang); 0034 0035 var flightNum = detailsRoot.recursiveContent.match(/\s([A-Z0-9]{2})(\d{1,4})\b/); 0036 res.reservationFor.flightNumber = flightNum[2]; 0037 res.reservationFor.airline.iataCode = flightNum[1]; 0038 0039 reservations.push(res); 0040 } 0041 0042 return reservations; 0043 } 0044 0045 function parsePdfBoardingPass(pdf, node, triggerNode) { 0046 let res = triggerNode.result[0]; 0047 const page = pdf.pages[triggerNode.location]; 0048 const topRight = page.textInRect(0.5, 0.0, 1.0, 0.5); 0049 const times = topRight.match(/(\d{2}:\d{2}) (?:H|Uhr) +(\d{2}:\d{2}) (?:H|Uhr)/); 0050 res.reservationFor.departureTime = JsonLd.toDateTime(times[1], "hh:mm", "en"); 0051 res.reservationFor.arrivalTime = JsonLd.toDateTime(times[2], "hh:mm", "en"); 0052 const topLeft = page.textInRect(0.0, 0.0, 0.5, 1.0); 0053 const grp = topLeft.match(/(?:Group|Grupo|Gruppe) +(\d)/i); 0054 if (grp) { 0055 res.boardingGroup = grp[1]; 0056 } 0057 return res; 0058 }