File indexing completed on 2024-12-29 04:51:05
0001 /* 0002 SPDX-FileCopyrightText: 2018 Sune Vuorela <sune@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 /* 0008 There seems to just be a pdf with at least 3 different formats in my collection. 0009 The newest one seems to have a first line that starts with BOARDING PASS, and the header of the actual data is 0010 FLIGHT DATE TIME FROM TO CLASS GATE SEQ# ZONE SEAT BOARDING 0011 0012 The older ones starts with a different first line, and have different headers. 0013 0014 I wonder if that's something that could be used for detecting types. But the older formats in my collection are from first half of 2017 and older. 0015 But we need more data. 0016 0017 */ 0018 0019 function main(pdf, node, triggerNode) { 0020 const text = pdf.pages[triggerNode.location].text; 0021 if (!text.match(/BOARDING PASS/)) 0022 return null; 0023 0024 var lines = text.split('\n'); 0025 0026 var state = 0; 0027 var flights = []; 0028 for(var i = 0 ; i < lines.length; i++) { 0029 var line = lines[i]; 0030 if (line.match(/FLIGHT\s+DATE\s+TIME\s+FROM\s+TO\s+CLASS\s+GATE\s+SEQ#\s+(:?ZONE|GROUP)\s+SEAT\s+BOARDING/i)) 0031 { 0032 if (state !== 0) console.log("ISSUE") 0033 lastFlight = {}; 0034 state = 1; 0035 continue; 0036 } 0037 if (state === 0) { 0038 continue; 0039 } 0040 if (state === 1) { 0041 var times = line.match(/\w+\s+(\d{2} [a-zA-Z]{3})\.?\s+(\d{2}:\d{2})\s+.*(\d{2}:\d{2}).*/); 0042 if (!times) { 0043 continue; 0044 } 0045 let flight = triggerNode.result[flights.length]; 0046 flight.reservationFor.departureTime = JsonLd.toDateTime(times[1] + ' ' + times[2],'dd MMM hh:mm', 'en'); 0047 flight.reservationFor.boardingTime = JsonLd.toDateTime(times[1] + ' ' + times[3],'dd MMM hh:mm', 'en'); 0048 flights.push(flight); 0049 continue; 0050 } 0051 } 0052 0053 return flights; 0054 }