File indexing completed on 2024-12-29 04:51:03
0001 /* 0002 SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 function extractEvent(ev) { 0007 let res = JsonLd.newLodgingReservation(); 0008 res.checkinTime = ev.dtStart; 0009 res.checkoutTime = ev.dtEnd; 0010 const subject = ev.summary.match(/(.*) - ([^,\n]*)(?:, ([A-Z\d]+))?/); 0011 res.underName.name = subject[1]; 0012 res.reservationFor.name = subject[2]; 0013 res.reservationNumber = subject[3]; 0014 res.reservationFor.address.addressLocality = ev.location; 0015 const desc = ev.description.match(/Hotel \(.*\)\n.*\n(.*)\n.*\n(.*)\n\n.*: (.*)\n/); 0016 res.reservationFor.address.streetAddress = desc[1]; 0017 res.reservationFor.address.postalCode = desc[2]; 0018 res.reservationFor.telephone = '+' + desc[3]; 0019 return res; 0020 } 0021 0022 function extractPdf(pdf) { 0023 const text = pdf.text; 0024 0025 let links = []; 0026 for (const page of pdf.pages) { 0027 for (const link of page.links) { 0028 links.push(link); 0029 } 0030 } 0031 0032 let idx = 0; 0033 let linkIdx = 1; 0034 let reservations = []; 0035 while (true) { 0036 const hotel = text.substr(idx).match(/(\S.*\S) +(#[0-9A-Z]+)\n/); 0037 if (!hotel) 0038 break; 0039 idx += hotel.index + hotel[0].length; 0040 0041 let res = JsonLd.newLodgingReservation(); 0042 res.reservationFor.name = hotel[1]; 0043 res.reservationNumber = hotel[2]; 0044 const dates = text.substr(idx).match(/CHECK-IN +CHECK-OUT\n *(\d{1,2}[ -][a-z]{3}[ -]\d{4}) +(\d{1,2}[ -][a-z]{3}[ -]\d{4})\n.*\n([\s\S]+?,[ \n][A-Z]{3})\n/); 0045 res.checkinTime = JsonLd.toDateTime(dates[1], ["d-MMM-yyyy", "d MMM yyyy"], ["en", "it"]); 0046 res.checkoutTime = JsonLd.toDateTime(dates[2], ["d-MMM-yyyy", "d MMM yyyy"], ["en", "it"]); 0047 0048 const addr = dates[3].replace('\n', ' ').split(','); 0049 res.reservationFor.address.streetAddress = addr[0]; 0050 res.reservationFor.address.addressLocality = addr[1]; 0051 if (addr.length == 5) 0052 res.reservationFor.address.addressRegion = addr[addr.length - 3]; 0053 res.reservationFor.address.postalCode = addr[addr.length - 2]; 0054 res.reservationFor.address.addressCountry = addr[addr.length - 1]; 0055 0056 const loc = links[linkIdx++].url.match(/(-?\d+\.\d+),(-?\d+\.\d+)/); 0057 res.reservationFor.geo.latitude = loc[1]; 0058 res.reservationFor.geo.longitude = loc[2]; 0059 reservations.push(res); 0060 } 0061 return reservations; 0062 }