diff --git a/src/extractors/extractors.qrc b/src/extractors/extractors.qrc --- a/src/extractors/extractors.qrc +++ b/src/extractors/extractors.qrc @@ -40,5 +40,7 @@ swiss.json swiss.js swiss-pkpass.js + hertz.js + hertz.json diff --git a/src/extractors/hertz.js b/src/extractors/hertz.js new file mode 100644 --- /dev/null +++ b/src/extractors/hertz.js @@ -0,0 +1,99 @@ +/* + Copyright (c) 2018 Laurent Montel + + 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("RentalCarReservation"); + + var bookingRef = text.match(/Your reservation number is\s+([A-Z0-9-]+)\s+/); + if (!bookingRef) + return null; + res.reservationNumber = bookingRef[1]; + + var idx = bookingRef.index + bookingRef[0].length; + res.underName = JsonLd.newObject("Person"); + var name = text.substr(idx).match(/Customer Name:\s+(.*)/); + if (!name) + return null; + res.underName.name = name[1]; + idx += name.index + name[0].length; + + var renting = text.substr(idx).match(/Renting\s+/); + if (!renting) + return null; + idx += renting.index + renting[0].length; + var cityPickup = text.substr(idx).match(/City:\s+(.*)/); + res.pickUpLocation = JsonLd.newObject("Place"); + res.pickUpLocation.address = JsonLd.newObject("PostalAddress"); + res.pickUpLocation.address.addressLocality = cityPickup[1]; + idx += cityPickup.index + cityPickup[0].length; + + var locationPickup = text.substr(idx).match(/Location:\s+(.*)/); + res.pickUpLocation.name = locationPickup[1]; + idx += locationPickup.index + locationPickup[0].length; + + var addressPickup = text.substr(idx).match(/Address:\s+(.*)/); + res.pickUpLocation.address.streetAddress = addressPickup[1]; + idx += addressPickup.index + addressPickup[0].length; + + //Problem for parsing date/time ! + var pickUpDate = text.substr(idx).match(/Date\/Time:\s+(.*)/) + if (!pickUpDate) + return null; + res.pickupTime = JsonLd.toDateTime(pickUpDate[1], "ddd dd MMM yyyy hh:mm A", "en"); + idx += pickUpDate.index + pickUpDate[0].length; + + + //Add tel/email etc. + + var returnCar = text.substr(idx).match(/Return\s+/); + if (!returnCar) + return null; + idx += returnCar.index + returnCar[0].length; + var cityDropoff = text.substr(idx).match(/City:\s+(.*)/); + res.dropOffLocation = JsonLd.newObject("Place"); + res.dropOffLocation.address = JsonLd.newObject("PostalAddress"); + res.dropOffLocation.address.addressLocality = cityDropoff[1]; + idx += cityDropoff.index + cityDropoff[0].length; + + var locationDropOff = text.substr(idx).match(/Location:\s+(.*)/); + res.dropOffLocation.name = locationDropOff[1]; + idx += locationDropOff.index + locationDropOff[0].length; + + var addressDropOff = text.substr(idx).match(/Address:\s+(.*)/); + res.dropOffLocation.address.streetAddress = addressDropOff[1]; + idx += addressDropOff.index + addressDropOff[0].length; + + var dropOffDate = text.substr(idx).match(/Date\/Time:\s*(.*)/) + if (!dropOffDate) + return null; + + //Need to convert datetime as "Date/Time: MON 22 MAY 2017 09:30 AM" + res.dropoffTime = JsonLd.toDateTime(dropOffDate[1], "ddd dd MMM yyyy hh:mm A", "en"); + idx += dropOffDate.index + dropOffDate[0].length; + + res.reservationFor = JsonLd.newObject("RentalCar"); + //Fix me it seems to use 2 lines ! + var vehiculeType = text.substr(idx).match(/Vehicle:\s+(.*)\s+/) + if (!vehiculeType) + return null; + res.reservationFor.model = vehiculeType[1]; + idx += vehiculeType.index + vehiculeType[0].length; + + return res; +} diff --git a/src/extractors/hertz.json b/src/extractors/hertz.json new file mode 100644 --- /dev/null +++ b/src/extractors/hertz.json @@ -0,0 +1,6 @@ +{ + "filter": [ + { "header": "From", "match": "@hertz.com" } + ], + "script": "hertz.js" +}