Commit 16ff2755 authored by Volker Krause's avatar Volker Krause
Browse files

Add Eventbrite extractor script

This does two things:
* Fix messed up address information from their structured data.
* Attempt to find the corresponding barcode in an attached PDF.
parent 2dc7df32
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function fixAddress(content, node) {
if (node.result.length != 1) {
return;
}
// streetAddress duplicates city and zip code without proper separation in
// about half their emails...
var res = node.result[0];
var addr = res.reservationFor.location.address;
if (addr.streetAddress.endsWith(addr.addressLocality)) {
addr.streetAddress = addr.streetAddress.substr(0, addr.streetAddress.length - addr.addressLocality.length).trim();
}
if (addr.streetAddress.endsWith(addr.postalCode)) {
addr.streetAddress = addr.streetAddress.substr(0, addr.streetAddress.length - addr.postalCode.length);
}
res.reservationFor.location.address = addr;
return res;
}
function findBarcode(content, node) {
if (node.result.length != 1) {
return;
}
const pdfs = node.findChildNodes({ mimeType: "application/pdf", scope: "Descendants" });
if (pdfs.length == 1) {
const images = pdfs[0].findChildNodes({ mimeType: "internal/qimage", scope: "Descendants" });
var barcode = undefined;
for (const image of images) {
if (!image.childNodes || image.childNodes.length != 1 || image.childNodes[0].mimeType != "text/plain") {
continue;
}
if (barcode && barcode != image.childNodes[0].content) {
return;
}
barcode = image.childNodes[0].content;
}
if (barcode) {
var res = node.result[0];
if (res.reservedTicket == undefined)
res.reservedTicket = JsonLd.newObject("Ticket");
res.reservedTicket.ticketToken = "qrCode:" + barcode;
return res;
}
}
}
[
{
"filter": [
{
"field": "From",
"match": "@order.eventbrite.com",
"mimeType": "message/rfc822",
"scope": "Ancestors"
},
{
"field": "From",
"match": "orders@eventbrite.com",
"mimeType": "message/rfc822",
"scope": "Ancestors"
}
],
"function": "fixAddress",
"mimeType": "text/html",
"script": "eventbrite.js"
},
{
"filter": [
{
"field": "From",
"match": "@order.eventbrite.com",
"mimeType": "message/rfc822",
"scope": "Current"
},
{
"field": "From",
"match": "orders@eventbrite.com",
"mimeType": "message/rfc822",
"scope": "Current"
}
],
"function": "findBarcode",
"mimeType": "message/rfc822",
"script": "eventbrite.js"
}
]
......@@ -48,6 +48,8 @@
<file>eurowings.json</file>
<file>eurowings.js</file>
<file>eurowings-pkpass.js</file>
<file>eventbrite.json</file>
<file>eventbrite.js</file>
<file>fcmtravel.json</file>
<file>fcmtravel.js</file>
<file>flixbus.json</file>
......
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