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

0001 /*
0002     SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 function main(pdf, node) {
0008     var barcodes = node.findChildNodes({ mimeType: "text/plain", match: ".*", scope: "Descendants" });
0009     var results = new Array();
0010     for (barcode of barcodes) {
0011         if (barcode.location != undefined)
0012             results.push(parsePage(pdf.pages[barcode.location], barcode.content));
0013     }
0014     return results;
0015 }
0016 
0017 function parsePage(page, barcode) {
0018     const lines = page.text.split("\n")
0019     
0020     const res = JsonLd.newEventReservation()
0021     
0022     let date = ""
0023     let startTime = ""
0024     let endTime = ""
0025     
0026     res.reservedTicket.ticketToken = "qrCode:" + barcode
0027     
0028     const address = JsonLd.newObject("PostalAddress")
0029     address.addressCountry = "DE"
0030     address.addressLocality = "Berlin"
0031     address.addressRegion = "Berlin"
0032     address.postalCode = "10319"
0033     address.streetAddress = "Am Tierpark 125"
0034     
0035     res.reservationFor.location.address = address
0036     res.reservationFor.name = "Tierpark Berlin"
0037     
0038     for (line of lines) {
0039         
0040         const nameMatch = line.match(/Name:[ ]*([^\s].*)/)
0041         if (nameMatch) {
0042             res.underName.name = nameMatch[1]
0043         }
0044         
0045         const bookingCodeMatch = line.match(/Booking code:[ ]*([^\s].*)/)
0046         if (bookingCodeMatch) {
0047             res.reservationNumber = bookingCodeMatch[1]
0048         }
0049         
0050         const dateMatch = line.match(/Valid on:[ ]*([0-9]{1,2} [a-zA-Z]+ [0-9]{4})/)
0051         if (dateMatch) {
0052             date = dateMatch[1]
0053         }
0054         
0055         const timeMatch = line.match(/Time slot:[ ]*([0-9]{1,2}:[0-9]{1,2} (AM|PM)) - ([0-9]{1,2}:[0-9]{1,2} (AM|PM))/)
0056         if (timeMatch) {
0057             startTime = timeMatch[1]
0058             endTime = timeMatch[3]
0059         }
0060     }
0061 
0062     res.reservationFor.startDate = JsonLd.toDateTime(date + " " + startTime, "dd MMM yyyy h:mm ap", "en")
0063     res.reservationFor.endDate = JsonLd.toDateTime(date + " " + endTime, "dd MMM yyyy h:mm ap", "en")
0064 
0065     return res;
0066 }