File indexing completed on 2024-12-29 04:51:05
0001 /* 0002 SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 function main(content) { 0008 0009 const resId = content.match(/Buchungsnummer:\n?\s*(.+)/)[1] 0010 0011 const arrivalDate = content.match(/Anreisetag:\n? *(.+)/)[1] 0012 const departureDate = content.match(/Abreisetag:\n? *(.+)/)[1] 0013 0014 const guestName = content.match(/Gastname:\n? *(?:Herr|Frau)? ?(.+)/)[1] 0015 0016 const addressBlock = content.match(/Ihr\n(.*)\n(.*)\n(.*)/) 0017 0018 const hotelName = addressBlock[1] 0019 0020 const street = addressBlock[2] 0021 0022 const cityLine = addressBlock[3].match(/([0-9]+) (.*)/) 0023 0024 const address = JsonLd.newObject("PostalAddress") 0025 address.addressCountry = "DE" 0026 address.addressLocality = cityLine[2] 0027 address.postalCode = cityLine[1] 0028 address.streetAddress = street 0029 0030 const telephone = content.match(/Tel.: (.*)/)[1] 0031 const email = content.match(/E-Mail: +(.*)/)[1] 0032 0033 const price = content.match(/Gesamtpreis:\n? *(.*) EUR/)[1].replace(',', '.') 0034 0035 const numberAdults = content.match(/Anzahl der Erwachsene[rn]:\n? *([0-9]+)/)[1] 0036 0037 const numberChildren = content.match(/Anzahl der Kinder:\n? *([0-9]+)/); 0038 0039 var res = JsonLd.newLodgingReservation() 0040 0041 res.reservationFor.name = addressBlock[1] 0042 0043 res.reservationNumber = resId 0044 res.checkinTime = JsonLd.toDateTime(arrivalDate, "dd.MM.yyyy", "de") 0045 res.checkoutTime = JsonLd.toDateTime(departureDate, "dd.MM.yyyy", "de") 0046 0047 res.reservationFor.telephone = telephone 0048 res.reservationFor.email = email 0049 0050 res.reservationFor.address = address 0051 0052 res.underName.name = guestName 0053 0054 res.totalPrice = price 0055 res.priceCurrency = "EUR" 0056 0057 res.reservationFor.numAdults = numberAdults 0058 res.reservationFor.numChildren = numberChildren ? numberChildren[1] : undefined; 0059 0060 return res 0061 } 0062 0063 function parsePkPass(pass) 0064 { 0065 var res = JsonLd.newLodgingReservation(); 0066 res.reservationFor.name = pass.organizationName; 0067 res.checkinTime = JsonLd.toDateTime(pass.field['BGcheckin'].value.substr(0, 18), 'dd.MM.yyyy - hh:mm', 'de'); 0068 res.checkoutTime = JsonLd.toDateTime(pass.field['BGcheckout'].value.substr(0, 18), 'dd.MM.yyyy - hh:mm', 'de'); 0069 res.reservationFor.geo.latitude = pass.locations[0].latitude; 0070 res.reservationFor.geo.longitude = pass.locations[0].longitude; 0071 res.reservationFor.address.streetAddress = pass.field['address'].value; 0072 res.reservationFor.telephone = pass.field['phone'].value; 0073 res.reservationNumber = pass.field['bookId'].value; 0074 res.underName.name = pass.field['guestname'].value; 0075 return res; 0076 } 0077 0078 function parsePdf(pdf, node, triggerNode) 0079 { 0080 const page = pdf.pages[triggerNode.location]; 0081 let res = JsonLd.newLodgingReservation(); 0082 res.reservationNumber = page.text.match(/.*: ([A-Z0-9-]+)/)[1]; 0083 const leftCol = page.textInRect(0.0, 0.2, 0.5, 1.0); 0084 const dates = leftCol.match(/(\d\d\.\d\d.\d{4}).*(\d\d\.\d\d.\d{4})/); 0085 const times = leftCol.match(/(\d\d\:\d\d).*(\d\d\:\d\d)/); 0086 res.checkinTime = JsonLd.toDateTime(dates[1] + ' ' + times[1], 'dd.MM.yyyy hh:mm', 'de'); 0087 res.checkoutTime = JsonLd.toDateTime(dates[2] + ' ' + times[2], 'dd.MM.yyyy hh:mm', 'de'); 0088 const rightCol = page.textInRect(0.5, 0.2, 1.0, 1.0); 0089 const addr = rightCol.match(/.*\n(.*)\n(.*)\n(.*)/); 0090 res.reservationFor.name = addr[1]; 0091 res.reservationFor.address.streetAddress = addr[2]; 0092 res.reservationFor.address.addressLocality = addr[3]; 0093 res.reservationFor.telephone = page.links[0].url.substr(4); 0094 res.reservationFor.email = page.links[1].url.substr(7); 0095 res.reservationFor.geo = JsonLd.toGeoCoordinates(page.links[2].url); 0096 res.modifyReservationUrl = page.links[3].url; 0097 return res; 0098 }