File indexing completed on 2024-12-29 04:51:04
0001 /* 0002 SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 // Tickets can contain station names in multiple languages. Just use one of them, and let the DB API handle it 0007 function splitStationName(name) { 0008 if (name.includes("/")) { 0009 return name.split("/")[0] 0010 } 0011 0012 return name 0013 } 0014 0015 function extractPdf(pdf, node, triggerNode) { 0016 const text = pdf.pages[triggerNode.location].text; 0017 let reservations = []; 0018 let idx = 0; 0019 while (true) { 0020 const leg = text.substr(idx).match(/(\d{2}\/\d{2}\/\d{4}) (\d{2}:\d{2}) (\S.*\S) +-> +(\d{2}:\d{2}) (\S.*?\S) +(\S.*?) +(\S.*?) +(\S.*?)\n(?: {14}((?:\S| \S)*)(?: +(.*))?\n)?/); 0021 if (!leg) 0022 break; 0023 idx += leg.index + leg[0].length; 0024 0025 let res = JsonLd.clone(triggerNode.result[0]); 0026 res.reservationFor.departureTime = JsonLd.toDateTime(leg[1] + leg[2], "dd/MM/yyyyhh:mm", "en"); 0027 res.reservationFor.departureStation.name = splitStationName(leg[3] + (leg[9] ? leg[9] : "")); 0028 res.reservationFor.arrivalTime = JsonLd.toDateTime(leg[1] + leg[4], "dd/MM/yyyyhh:mm", "en"); 0029 res.reservationFor.arrivalStation.name = splitStationName(leg[5] + (leg[10] ? leg[10] : "")); 0030 res.reservationFor.trainNumber = leg[6]; 0031 res.reservedTicket.ticketedSeat.seatSection = leg[7] !== '*' ? leg[7] : undefined; 0032 res.reservedTicket.ticketedSeat.seatNumber = leg[8] !== '*' ? leg[8] : undefined; 0033 reservations.push(res); 0034 } 0035 0036 return reservations; 0037 }