diff --git a/autotests/unstructureddata/aohostels_1.json b/autotests/unstructureddata/aohostels_1.json new file mode 100644 index 0000000..c5d0bd9 --- /dev/null +++ b/autotests/unstructureddata/aohostels_1.json @@ -0,0 +1,29 @@ +[ + { + "@context": "http://schema.org", + "@type": "LodgingReservation", + "checkinTime": "2018-08-10T15:00:00", + "checkoutTime": "2018-08-18T10:00:00", + "reservationFor": { + "@type": "LodgingBusiness", + "address": { + "@type": "PostalAddress", + "addressCountry": "Österreich", + "addressLocality": "Wien", + "postalCode": "1100", + "streetAddress": "Sonnwendgasse 11" + }, + "geo": { + "@type": "GeoCoordinates", + "latitude": 48.1828498840332, + "longitude": 16.37863540649414 + }, + "name": "a&o Wien Hauptbahnhof" + }, + "reservationNumber": "AOI-XX-1234567", + "underName": { + "@type": "Person", + "name": "John Doe" + } + } +] diff --git a/autotests/unstructureddata/aohostels_1.txt b/autotests/unstructureddata/aohostels_1.txt new file mode 100644 index 0000000..7643e79 --- /dev/null +++ b/autotests/unstructureddata/aohostels_1.txt @@ -0,0 +1,30 @@ + HostelHotel_email + + Booking confirmation *Thank you for +booking through aohostels.com.* + +When making inquiries further to your booking and on arrival at A&O HOTELS +and HOSTELS, please provide us with your booking confirmation number + + *Hint:* Non refundable booking We wish you a pleasant stay, + + Your A&O Team *AOI-XX-1234567* + Your travel details Booking no. AOI-XX-1234567 Arrival + 10.08.2018 Departure 18.08.2018 Details 8 nights +Persons 1 adult Payment Visa / MasterCard / Amex Total Sum +999,99 € + including VAT and statutory city tax Map: How to find us + + Travel Information Reservation is made on the name +*First name* John *Last name* Doe *Address* Random Street 42 +*ZIP / City* 54321 Somewhere *Country* DEU *Email* null@kde.org + Your booked house a&o Wien Hauptbahnhof + Sonnwendgasse 11 + 1100 Wien + Österreich + +43 1 602 1234 5678 + AO-XX-XX@aohostels.com + Room selection 1 Single room (for 1 +adult ) You stay in a hotel single room with private facilities and +TV. Bed linen and towel included. Additionally, you can use free Wi-Fi in +your room. diff --git a/src/extractors/aohostels.js b/src/extractors/aohostels.js new file mode 100644 index 0000000..b09d6bb --- /dev/null +++ b/src/extractors/aohostels.js @@ -0,0 +1,81 @@ +/* + Copyright (c) 2018 Volker Krause + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +function main(text) { + var res = JsonLd.newObject("LodgingReservation"); + + var bookingRef = text.match(/Booking no\.\s+([A-Z0-9-]+)\s+/); + if (!bookingRef) + return null; + res.reservationNumber = bookingRef[1]; + var idx = bookingRef.index + bookingRef[0].length; + + var arrivalDate = text.substr(idx).match(/Arrival\s+(\d{1,2}\.\d{1,2}\.\d{4})\s+/) + if (!arrivalDate) + return null; + res.checkinTime = JsonLd.toDateTime(arrivalDate[1] + " 15:00", "dd.MM.yyyy hh:mm", "en"); + idx += arrivalDate.index + arrivalDate[0].length; + + var departureDate = text.substr(idx).match(/Departure\s+(\d{1,2}\.\d{1,2}\.\d{4})\s+/) + if (!departureDate) + return null; + res.checkoutTime = JsonLd.toDateTime(departureDate[1] + " 10:00", "dd.MM.yyyy hh:mm", "en"); + idx += departureDate.index + departureDate[0].length; + + res.reservationFor = JsonLd.newObject("LodgingBusiness"); + res.reservationFor.geo = JsonLd.newObject("GeoCoordinates"); + var geo = text.substr(idx).match(/google.com\/maps\/place\/([0-9\.]+),([0-9\.]+)>/); + if (geo) { + res.reservationFor.geo.latitude = geo[1]; + res.reservationFor.geo.longitude = geo[2]; + } + + res.underName = JsonLd.newObject("Person"); + var name = text.substr(idx).match(/\*First name\*\s+([^\s{2}]+)\s{2,}/); + if (!name) + return null; + res.underName.name = name[1]; + idx += name.index + name[0].length; + name = text.substr(idx).match(/\*Last name\*\s+([^\s{2}]+)\s{2,}/); + if (!name) + return null; + res.underName.name += ' ' + name[1]; + idx += name.index + name[0].length; + + var hotel = text.substr(idx).match(/Your booked house\s+/); + if (!hotel) + return null; + idx += hotel.index + hotel[0].length; + hotel = text.substr(idx).split(/\s{2,}/); + res.reservationFor.name = hotel[0]; + res.reservationFor.address = JsonLd.newObject("PostalAddress"); + res.reservationFor.address.streetAddress = hotel[1]; + var city = hotel[2].match(/(\d+)\s(.*)/); + if (city) { + res.reservationFor.address.postalCode = city[1]; + res.reservationFor.address.addressLocality = city[2]; + } else { + res.reservationFor.address.addressLocality = hotel[2]; + } + res.reservationFor.address.addressCountry = hotel[3]; + res.reservationFor.telephone = hotel[4]; + res.reservationFor.email = hotel[5]; + + return res; +} diff --git a/src/extractors/aohostels.json b/src/extractors/aohostels.json new file mode 100644 index 0000000..f4f00c0 --- /dev/null +++ b/src/extractors/aohostels.json @@ -0,0 +1,6 @@ +{ + "filter": [ + { "header": "From", "match": "@aohostels.com" } + ], + "script": "aohostels.js" +} diff --git a/src/extractors/extractors.qrc b/src/extractors/extractors.qrc index 0673738..b18a690 100644 --- a/src/extractors/extractors.qrc +++ b/src/extractors/extractors.qrc @@ -1,30 +1,32 @@ amadeus.json amadeus.js + aohostels.json + aohostels.js brusselsairlines.json brusselsairlines.js czechrailways.json czechrailways.js deutschebahn.json deutschebahn.js eurowings.json eurowings.js eurowings-pkpass.js fcmtravel.json fcmtravel.js iberia.json iberia.js klm.json klm.js lufthansa.json lufthansa-pkpass.js regiojet.json regiojet.js sncf.json sncf.js swiss.json swiss.js swiss-pkpass.js