Commit 0d029a2a authored by Volker Krause's avatar Volker Krause
Browse files

Extend the event reservation template

Also, clean up extractor scripts doing things already provided by the
respective templates.
parent 52945d6e
......@@ -132,6 +132,9 @@ QJSValue KItinerary::JsApi::JsonLd::newEventReservation() const
const auto ticket = newObject(QStringLiteral("Ticket"));
res.setProperty(QStringLiteral("reservedTicket"), ticket);
const auto person = newObject(QStringLiteral("Person"));
res.setProperty(QStringLiteral("underName"), person);
return res;
}
......
......@@ -4,15 +4,6 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function makeStation(name)
{
var station = JsonLd.newObject("TrainStation");
station.name = name;
station.address = JsonLd.newObject("PostalAddress");
station.address.addressCountry = "KR"; // Korail only serves Korea
return station;
}
function main(html) {
var bookingYear = html.eval("//table//table//table/tr[3]")[0].recursiveContent.match(/(\d{4}.)/)[1];
if (!bookingYear)
......@@ -24,8 +15,7 @@ function main(html) {
var reservations = new Array();
while (!tab.isNull) {
var res = JsonLd.newObject("TrainReservation");
res.reservationFor = JsonLd.newObject("TrainTrip");
var res = JsonLd.newTrainReservation();
var cell = tab.firstChild;
var date = bookingYear + cell.recursiveContent;
......@@ -34,11 +24,13 @@ function main(html) {
cell = cell.nextSibling;
res.reservationFor.trainName = cell.recursiveContent;
cell = cell.nextSibling;
res.reservationFor.departureStation = makeStation(cell.recursiveContent);
res.reservationFor.departureStation.name = cell.recursiveContent;
res.reservationFor.departureStation.address.addressCountry = "KR"; // Korail only serves Korea
cell = cell.nextSibling;
res.reservationFor.departureTime = JsonLd.toDateTime(date + " " + cell.recursiveContent, "yyyy년M월d일 hh:mm", "kr");
cell = cell.nextSibling;
res.reservationFor.arrivalStation = makeStation(cell.recursiveContent);
res.reservationFor.arrivalStation.name = cell.recursiveContent;
res.reservationFor.arrivalStation.address.addressCountry = "KR";
cell = cell.nextSibling;
res.reservationFor.arrivalTime = JsonLd.toDateTime(date + " " + cell.recursiveContent, "yyyy년M월d일 hh:mm", "kr");
......
......@@ -19,15 +19,13 @@ function parseDateTime(text) {
function parseHtml(doc) {
var res = JsonLd.newObject("LodgingReservation");
res.reservationFor = JsonLd.newObject("LodgingBusiness");
var res = JsonLd.newLodgingReservation();
var nameElem = doc.eval("//td[@class=\"title-hotel\"]")[0];
res.reservationFor.name = nameElem.content;
var addrElem = nameElem.parent.nextSibling.nextSibling.nextSibling.firstChild;
var addr = addrElem.content.match(/(.*), ?([^,]*)/);
res.reservationFor.address = JsonLd.newObject("PostalAddress");
res.reservationFor.address.streetAddress = addr[1];
res.reservationFor.address.addressLocality = addr[2];
res.reservationFor.url = lastChild(addrElem).attribute("href");
......@@ -48,7 +46,6 @@ function parseHtml(doc) {
res.reservationNumber = bookingRef.content;
var bookingRow = bookingRef.parent.nextSibling.nextSibling;
res.underName = JsonLd.newObject("Person");
res.underName.name = bookingRow.firstChild.nextSibling.content;
bookingRow = bookingRow.nextSibling.nextSibling;
......
......@@ -18,7 +18,6 @@ function parsePage(page, barcode) {
const lines = page.text.split("\n")
const res = JsonLd.newEventReservation()
res.underName = JsonLd.newObject("Person");
let date = ""
let startTime = ""
......
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