Unverified Commit 8fe0e429 authored by Luca Beltrame's avatar Luca Beltrame
Browse files

Add extractors for Kintetsu Railway Limited Express reservations

The format is free-form text, so regular expressions are necessary.
Everything but the train name/number (which is not in the email sent by
their system) is extracted.

Test Plan: Manually fed an email in kitinerary-workbench, got data extracted.

Reviewers: vkrause

Reviewed By: vkrause

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D26257
parent a06afded
Copyright (c) 2019 Luca Beltrame <lbeltrame@kde.org>
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
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.
var reservationRegex = /Reservation number: (.*)/;
// Format: Station name(Station number)
var departureRegex = /Departure: (.*)(\(.*\))/;
var destinationRegex = /Arrival: (.*)(\(.*\))/;
var seatRegex = /Seat No.: (.*){1,}/;
var nameRegex = /To (.*)/;
var departureDateRegex = /Date of boarding: (.*?),(.*)/;
// Has a day of week as first item
var departureTimeRegex = /Departure time: (.*)/;
var arrivalTimeRegex = /Arrival time: (.*)/;
var coachRegex = /Car No.: (.*)/;
function main(text) {
var res = JsonLd.newTrainReservation();
res.reservationNumber = text.match(reservationRegex)[1];
res.underName.name = text.match(nameRegex)[1];
res.reservationFor.departureStation.name = text.match(departureRegex)[1];
res.reservationFor.arrivalStation.name = text.match(destinationRegex)[1];
var depDate = text.match(departureDateRegex)[2];
var arrDate = text.match(departureDateRegex)[2];
var depTime = text.match(departureTimeRegex)[1];
var arrTime = text.match(departureTimeRegex)[1];
var depDateTime = depDate + " " + depTime;
var arrDateTime = arrTime + " " + arrTime;
var seats = text.match(seatRegex)[1];
res.reservationFor.departureTime = JsonLd.toDateTime(depDateTime, "dd MMM, yyyy hh:mm", "jp")
res.reservationFor.arrivalTime = JsonLd.toDateTime(arrDateTime, "dd MMM, yyyy hh:mm", "jp")
// TODO: Handle the fact that there are multiple seats but only one name with reservation
res.reservedTicket.ticketedSeat.seatNumber = text.match(seatRegex)[1];
res.reservedTicket.ticketedSeat.seatSection = text.match(coachRegex)[1];
return res;
"filter": [
"header": "From",
"match": "@rw.kintetsu.co.jp",
"type": "Email"
"function": "main",
"script": "kintetsu.js",
"type": "text"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment