Commit bccb8796 authored by Volker Krause's avatar Volker Krause
Browse files

Make the Norwegian extractor handle boarding passes with a barcode too

parent c7f35879
......@@ -15,43 +15,60 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
function parsePage(page)
{
var res = JsonLd.newFlightReservation();
var pnr = page.text.match(/\nBooking reference.*(.{6})\n/);
if (!pnr)
return null;
res.reservationNumber = pnr[1];
var name = page.text.match(/\nPassenger\s+(?:\S+)? ([A-Z ]+)\/(.+)\n/);
res.underName.familyName = name[1];
res.underName.givenName = name[2];
var flight = page.text.match(/\nFlight.*?(\S{2})(\d{1,4}) - (.*)\n/);
res.reservationFor.airline.iataCode = flight[1];
res.reservationFor.flightNumber = flight[2];
var dep = page.text.match(/\nDeparture.*(\d{2}:\d{2}) (.*) \(([A-Z]{3})\)(.*)\n/);
res.reservationFor.departureAirport.name = dep[2];
res.reservationFor.departureAirport.iataCode = dep[3];
res.reservationFor.departureTerminal = dep[4];
res.reservationFor.departureTime = JsonLd.toDateTime(flight[3] + dep[1], "dd MMM yyyyhh:mm", "en");
var arr = page.text.match(/\Arrival.*(\d{2}:\d{2}) (.*) \(([A-Z]{3})\)(.*)\n/);
res.reservationFor.arrivalAirport.name = arr[2];
res.reservationFor.arrivalAirport.iataCode = arr[3];
res.reservationFor.arrivalTerminal = arr[4];
res.reservationFor.arrivalTime = JsonLd.toDateTime(flight[3] + arr[1], "dd MMM yyyyhh:mm", "en");
var seat = page.text.match(/Seat.* (\d{1,3}[A-J]) .*\n/);
if (seat) {
res.airplaneSeat = seat[1];
}
var group = page.text.match(/Boarding group.* (\w)\n/);
if (group) {
res.boardingGroup = group[1];
}
if (Context.barcode) {
res.reservedTicket.ticketToken = Context.barcode;
}
return res;
}
function extractPdf(pdf) {
if (Context.pdfPageNumber >= 0) {
return parsePage(pdf.pages[Context.pdfPageNumber]);
}
var results = new Array();
var pages = pdf.pages;
for (var i = 0; i < pages.length; ++i) {
var page = pages[i];
var res = JsonLd.newFlightReservation();
var pnr = page.text.match(/\nBooking reference.*(.{6})\n/);
res.reservationNumber = pnr[1];
var name = page.text.match(/\nPassenger\s+(?:\S+)? ([A-Z ]+)\/(.+)\n/);
res.underName.familyName = name[1];
res.underName.givenName = name[2];
var flight = page.text.match(/\nFlight.*?(\S{2})(\d{1,4}) - (.*)\n/);
res.reservationFor.airline.iataCode = flight[1];
res.reservationFor.flightNumber = flight[2];
var dep = page.text.match(/\nDeparture.*(\d{2}:\d{2}) (.*) \(([A-Z]{3})\)(.*)\n/);
res.reservationFor.departureAirport.name = dep[2];
res.reservationFor.departureAirport.iataCode = dep[3];
res.reservationFor.departureTerminal = dep[4];
res.reservationFor.departureTime = JsonLd.toDateTime(flight[3] + dep[1], "dd MMM yyyyhh:mm", "en");
var arr = page.text.match(/\Arrival.*(\d{2}:\d{2}) (.*) \(([A-Z]{3})\)(.*)\n/);
res.reservationFor.arrivalAirport.name = arr[2];
res.reservationFor.arrivalAirport.iataCode = arr[3];
res.reservationFor.arrivalTerminal = arr[4];
res.reservationFor.arrivalTime = JsonLd.toDateTime(flight[3] + arr[1], "dd MMM yyyyhh:mm", "en");
var seat = page.text.match(/Seat.* (\d{1,2}[A-J]) .*\n/);
if (seat) {
res.airplaneSeat = seat[1];
}
results.push(res);
results.push(parsePage(pages[i]));
}
return results;
}
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