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

0001 /*
0002    SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
0003    SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 function extractPass(pass, node) {
0007     let res = node.result[0];
0008     res.reservationFor = JsonLd.newObject("BusTrip");
0009     res.reservationFor.departureTime =  JsonLd.toDateTime(pass.field["date"].value + ' ' + pass.field["origin"].value, "dd.MMM hh:mm", "en");
0010     res.reservationFor.departureBusStop = {
0011         '@type': 'BusStation',
0012         name: pass.field["origin_long"].value,
0013         address: {
0014             '@type': 'PostalAddress',
0015             addressLocality: pass.field["origin"].label
0016         },
0017         geo: {
0018             '@type': 'GeoCoordinates',
0019             latitude: pass.locations[0].latitude,
0020             longitude: pass.locations[0].longitude
0021         }
0022     }
0023     res.reservationFor.departurePlatform = pass.field["platform"].value;
0024     res.reservationFor.arrivalTime =  JsonLd.toDateTime(pass.field["date"].value + ' ' + pass.field["destination"].value, "dd.MMM hh:mm", "en");
0025     res.reservationFor.arrivalBusStop = {
0026         '@type': 'BusStation',
0027         name: pass.field["destination_long"].value,
0028         address: {
0029             '@type': 'PostalAddress',
0030             addressLocality: pass.field["destination"].label
0031         }
0032     };
0033     res.reservedTicket.ticketedSeat = {
0034         '@type': 'Seat',
0035         seatNumber: pass.field["tariff"].value.match(/\/(.*)/)[1]
0036     };
0037     return res;
0038 }
0039 
0040 function extractTicket(pdf, node, barcode) {
0041     const text = pdf.pages[barcode.location].text;
0042     let res = JsonLd.newBusReservation();
0043     res.underName.name = text.match(/^.*?: +(.*?)  /)[1];
0044     res.reservationNumber = barcode.content;
0045     const dep = text.match(/Departure: +(.*) \S+, (\d\d\.\d\d\.\d{4} \d\d:\d\d)/);
0046     res.reservationFor.departureBusStop.name = dep[1];
0047     res.reservationFor.departureTime = JsonLd.toDateTime(dep[2], 'dd.MM.yyyy hh:mm', 'en');
0048     const arr = text.match(/Arrival: +(.*) \S+, (\d\d\.\d\d\.\d{4} \d\d:\d\d)/);
0049     res.reservationFor.arrivalBusStop.name = arr[1];
0050     res.reservationFor.arrivalTime = JsonLd.toDateTime(arr[2], 'dd.MM.yyyy hh:mm', 'en');
0051     res.reservationFor.departurePlatform = text.match(/Platform: +(\S.*)/)[1];
0052     res.reservedTicket.ticketedSeat.seatNumber = text.match(/Seat: +(\S.*)/)[1];
0053     res.reservationFor.busNumber = text.match(/Bus line no: +(.*)  /)[1];
0054     res.reservedTicket.ticketToken = 'qrCode:' + barcode.content;
0055     ExtractorEngine.extractPrice(text, res);
0056     return res;
0057 }