File indexing completed on 2024-12-29 04:51:02
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 function parseConfirmation(html) { 0008 var res = JsonLd.newLodgingReservation(); 0009 0010 const content = html.root.recursiveContent; 0011 res.reservationNumber = content.match(/(?:Reservation number|Buchungsnummer):?\s*([0-9A-Z]+)/)[1]; 0012 0013 let dt = content.match(/(\d{2}[|/.]\d{2}[|/.]\d{4}).*(\d{2}[|/.]\d{2}[|/.]\d{4})/); 0014 if (!dt) // US format 0015 dt = content.match(/([A-Z][a-z]{2}\. \d{2}, \d{4}).*([A-Z][a-z]{2}\. \d{2}, \d{4})/); 0016 if (!dt) 0017 dt = content.match(/(\d{2} [A-Z][a-z]{2} \d{4}).*(\d{2} [A-Z][a-z]{2} \d{4})/); 0018 const formats = [ "dd.MM.yyyy", "dd/MM/yyyy", "MMM. dd, yyyy", "dd MMM yyyy"]; 0019 res.checkinTime = JsonLd.toDateTime(dt[1], formats, "en"); 0020 res.checkoutTime = JsonLd.toDateTime(dt[2], formats, "en"); 0021 0022 let hotelNode = html.eval('//table//table//table[@class="table-full"]'); 0023 if (!hotelNode || hotelNode.length === 0) 0024 hotelNode = html.eval('//table//table//table//table//tr/td/font/a/../../../..'); 0025 hotelContent = hotelNode[0].recursiveContent; 0026 hotelContent = hotelContent.replace(/\s+\n/, "\n"); 0027 0028 var hotel = hotelContent.match(/^(.*)\n+(.*\n.*)\n(?:.|\n)*Tel\s*:\s*([\d \/\+\(\)]+)\n(.+@.+?)[\s\n]/); 0029 if (hotel) { 0030 res.reservationFor.telephone = hotel[3]; 0031 res.reservationFor.email = hotel[4]; 0032 } else { 0033 // no contact information present 0034 hotel = hotelContent.match(/^(.*)\n+(.*\n.*)\n(?:.|\n)*/); 0035 } 0036 res.reservationFor.name = hotel[1]; 0037 0038 0039 var addr = hotel[2].match(/(.*)(?: - |\n)(.*) - (.*)/); 0040 res.reservationFor.address.streetAddress = addr[1]; 0041 res.reservationFor.address.addressLocality = addr[2]; 0042 res.reservationFor.address.addressCountry = addr[3]; 0043 0044 // this is in an HTML comment... 0045 if (html.rawData.match(/TARS - AH - Client - Cancellation - Email/)) { 0046 res.reservationStatus = "ReservationCancelled" 0047 } 0048 0049 return res; 0050 }