[pim/kitinerary] src/lib/scripts: Add extractor script for HVV ical events

Volker Krause <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 3b471245d927f92fc337ce3c35537a96c935447a by Volker Krause.
Committed on 16/07/2026 at 15:56.
Pushed by vkrause into branch 'master'.

Add extractor script for HVV ical events

M  +2    -0    src/lib/scripts/extractors.qrc
A  +37   -0    src/lib/scripts/hvv.js
A  +13   -0    src/lib/scripts/hvv.json

https://invent.kde.org/pim/kitinerary/-/commit/3b471245d927f92fc337ce3c35537a96c935447a

diff --git a/src/lib/scripts/extractors.qrc b/src/lib/scripts/extractors.qrc
index c31f0db3..be7b94c0 100644
--- a/src/lib/scripts/extractors.qrc
+++ b/src/lib/scripts/extractors.qrc
@@ -216,6 +216,8 @@
         <file>hostelworld.js</file>
         <file>hotels.com.json</file>
         <file>hotels.com.js</file>
+        <file>hvv.json</file>
+        <file>hvv.js</file>
         <file>iberia.json</file>
         <file>iberia.js</file>
         <file>impfzentrum_bayern.json</file>
diff --git a/src/lib/scripts/hvv.js b/src/lib/scripts/hvv.js
new file mode 100644
index 00000000..5f015b07
--- /dev/null
+++ b/src/lib/scripts/hvv.js
@@ -0,0 +1,37 @@
+// SPDX-FileCopyrightText: 2026 Volker Krause <[email protected]>
+// SPDX-License-Identifier: LGPL-2.0-or-later
+
+function extractPlatform(s)
+{
+    const p = s ? s.match(/Gleis (.*)/) : undefined;
+    return p ? p[1] : undefined;
+}
+
+function extractEvent(ev) {
+    let reservations = [];
+    let idx = 0;
+    while (true) {
+        const leg = ev.description.substr(idx).match(/\) (.*) ➔ (.*)\nAb (\d\d:\d\d) (.*?)(?: \((.*)\))?\nAn (\d\d:\d\d) (.*?)(?: \((.*)\))?\n/);
+        if (!leg)
+            break;
+        idx += leg.index + leg[0].length;
+        let res = JsonLd.newTrainReservation();
+        res.reservationFor.trainNumber = leg[1];
+        res.reservationFor.departureDay = ev.dtStart;
+        res.reservationFor.departureTime = leg[3];
+        res.reservationFor.departureStation.name = leg[4];
+        res.reservationFor.departurePlatform = extractPlatform(leg[5]);
+        res.reservationFor.arrivalTime = leg[6];
+        res.reservationFor.arrivalStation.name = leg[7];
+        res.reservationFor.arrivalPlatform = extractPlatform(leg[8]);
+
+        const busNum = leg[1].match(/(.*) \(Bus\)/);
+        if (busNum) {
+            res.reservationFor.trainNumber = busNum[1];
+            res = JsonLd.trainToBusReservation(res);
+        }
+
+        reservations.push(res);
+    }
+    return reservations;
+}
diff --git a/src/lib/scripts/hvv.json b/src/lib/scripts/hvv.json
new file mode 100644
index 00000000..e063ea29
--- /dev/null
+++ b/src/lib/scripts/hvv.json
@@ -0,0 +1,13 @@
+{
+    "filter": [
+        {
+            "field": "description",
+            "match": "https://geofox\\.hvv\\.de/",
+            "mimeType": "internal/event",
+            "scope": "Current"
+        }
+    ],
+    "function": "extractEvent",
+    "mimeType": "internal/event",
+    "script": "hvv.js"
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.