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

Port more extractor scripts away from the deprecated Context API

For ÖBB and VGN this has the nice side-effect that they are no longer tied
to a surrounding PDF but can also work on the raw binary barcode directly.
parent d27309d7
Pipeline #61758 passed with stages
in 12 minutes and 25 seconds
......@@ -35,8 +35,8 @@ regExMap['de_DE']['departureDate'] = /Abreise ([A-Z][a-z]+, [0-9]{1,2}\. \S+ [0-
regExMap['de_DE']['person'] = /Name des Gastes +(.*) Name des Gastes bearbeiten/;
regExMap['de_DE']['dateFormat'] = "dddd, d. MMMM yyyy hh:mm";
function main(text) {
if (Context.data)
function main(text, node) {
if (node.result.length > 0)
return null; // this is just backup if we have no structured data
var res = JsonLd.newLodgingReservation();
......@@ -87,9 +87,9 @@ function main(text) {
}
}
function parseHtml(doc)
function parseHtml(doc, node)
{
if (Context.data)
if (node.result.length > 0)
return null; // this is just backup if we have no structured data
var res = JsonLd.newLodgingReservation();
var elem = doc.eval("//table[@class=\"mg_conf_hotel_preview\"]")[0];
......
......@@ -4,13 +4,13 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function parsePdf(pdf)
function parsePdf(pdf, node, triggerNode)
{
if (!Context.data) {
if (!triggerNode.result) {
return null;
}
var ptTicket = Barcode.decodeUic9183(Context.barcode);
var ptTicket = triggerNode.content
var res = JsonLd.newEventReservation();
res.reservationFor.name = ptTicket.person.name;
res.reservationFor.location.name = "Congress Center Leipzig";
......@@ -29,7 +29,7 @@ function parsePdf(pdf)
res.reservationFor.endDate = end;
// search for the QR code with the actual event code
var images = pdf.pages[Context.pdfPageNumber].images;
var images = pdf.pages[triggerNode.location].images;
for (var i = 0; i < images.length; ++i) {
var code = Barcode.decodeQR(images[i]);
if (code) {
......@@ -40,7 +40,7 @@ function parsePdf(pdf)
// generate the second ticket for public transport
var pt = JsonLd.clone(res);
pt.reservedTicket.ticketToken = Context.data[0].reservedTicket.ticketToken;
pt.reservedTicket.ticketToken = triggerNode.result[0].reservedTicket.ticketToken;
pt.reservedTicket.name = "Public Transport";
var reservations = new Array();
......
{
"filter": [
{
"match": "uic:9997",
"field": "reservationFor.provider.identifier",
"mimeType": "application/ld+json",
"match": "9997",
"field": "carrierId",
"mimeType": "internal/uic9183",
"scope": "Descendants"
}
],
......
......@@ -4,9 +4,9 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function main(pass)
function main(pass, node)
{
var res = Context.data[0];
var res = node.result[0];
res.reservationFor.startDate = JsonLd.toDateTime(pass.field["reservation_time_from"].value, "dd.MM.yyyy", "de");
res.reservationFor.endDate = JsonLd.toDateTime(pass.field["reservation_time_till"].value, "dd.MM.yyyy", "de");
......
......@@ -4,9 +4,9 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function main(pass)
function main(pass, node)
{
var res = Context.data[0];
var res = node.result[0];
res.reservationFor.departureAirport.name = pass.field["origin"].label;
res.reservationFor.arrivalAirport.name = pass.field["destination"].label;
if (pass.field["operatingcarrier"])
......
......@@ -4,9 +4,9 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function main(content) {
function main(content, node) {
// convert QR download links into the actual QR codes
var res = Context.data;
var res = node.result;
for (var i = 0; i < res.length; ++i) {
var ticketToken = res[i].reservedTicket.ticketToken;
res[i].reservedTicket.ticketToken = ticketToken.replace(/^https?:\/\/api\.meinfernbus\.(..)\/qrcode\/..\//, "qrCode:https://shop.flixbus.$1/pdfqr/");
......
......@@ -4,11 +4,11 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function parseBookingConfirmation(html) {
if (Context.data.length != 1) {
function parseBookingConfirmation(html, node) {
if (node.result.length != 1) {
return;
}
var res = Context.data[0];
var res = node.result[0];
// augment checking times missing from schema.org annotations
var checkinTimeElems = html.eval('//*[@id="booking-summary-check-in-time"]');
......
......@@ -4,13 +4,13 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function main(pass)
function main(pass, node)
{
// if (pass.transitType != KPkPass.BoardinPass.Air) { // TODO this needs to be registered in the engine
// return null;
// }
var res = Context.data[0];
var res = node.result[0];
res.reservationFor.departureAirport.name = pass.field["origin"].label;
res.reservationFor.arrivalAirport.name = pass.field["destination"].label;
......
......@@ -4,12 +4,11 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function parsePdf(pdf) {
if (Context.data.length > 1) // not sure this can happen
function parseTicket(ticket, node) {
if (node.result.length > 1) // not sure this can happen
return;
var res = Context.data[0];
var ticket = Barcode.decodeUic9183(Context.barcode);
var res = node.result[0];
// decode 118199 vendor block
var block = ticket.block("118199");
......
{
"filter": [
{
"match": "uic:1181",
"field": "reservationFor.provider.identifier",
"mimeType": "application/ld+json",
"scope": "Descendants"
"match": "1181",
"field": "carrierId",
"mimeType": "internal/uic9183",
"scope": "Current"
}
],
"function": "parsePdf",
"function": "parseTicket",
"script": "oebb.js",
"mimeType": "application/pdf"
"mimeType": "internal/uic9183"
}
......@@ -15,9 +15,9 @@ function expandStationName(name)
return name;
}
function parsePkPass(pass)
function parsePkPass(pass, node)
{
var res = Context.data[0];
var res = node.result[0];
res.reservationFor = JsonLd.newObject("TrainTrip");
res.reservationFor.departureDay = JsonLd.toDateTime(pass.field["travelDate"].value, "dd/MM/yyyy", "en");
res.reservationFor.departureStation = JsonLd.newObject("TrainStation");
......
......@@ -4,14 +4,10 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function parsePdf(pdf) {
var ticket = Barcode.decodeUic9183(Context.barcode);
if (!ticket)
return null;
function parseTicket(ticket) {
var res = JsonLd.newTrainReservation();
res.reservationNumber = ticket.pnr;
res.reservedTicket.ticketToken = "aztectBin:" + Barcode.toBase64(Context.barcode);
res.reservedTicket.ticketToken = "aztectBin:" + Barcode.toBase64(ticket.rawData);
res.underName.name = ticket.ticketLayout.text(0, 0, 72, 1);
res.reservationFor.departureTime = JsonLd.toDateTime(ticket.ticketLayout.text(3, 0, 72, 1).match(/([\d\.: ]+)/)[1], "dd.MM.yyyy hh:mm", "de");
res.reservationFor.departureStation.name = ticket.ticketLayout.text(7, 0, 72, 1);
......
[
{
"mimeType": "application/pdf",
"mimeType": "internal/uic9183",
"filter": [
{ "field": "reservationFor.provider.identifier", "match": "3415", "mimeType": "application/ld+json", "scope": "Descendants" }
{ "field": "carrierId", "match": "3415", "mimeType": "internal/uic9183", "scope": "Current" }
],
"script": "vgn.js",
"function": "parsePdf"
"function": "parseTicket"
}
]
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