File indexing completed on 2024-12-29 04:51:04
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 function main(html) { 0008 var bookingYear = html.eval("//table//table//table/tr[3]")[0].recursiveContent.match(/(\d{4}.)/)[1]; 0009 if (!bookingYear) 0010 return null; 0011 0012 var tab = html.eval("//table//table//table//table//tr")[1]; // 0 is the table header 0013 if (!tab || tab.isNull) 0014 return null; 0015 0016 var reservations = new Array(); 0017 while (!tab.isNull) { 0018 var res = JsonLd.newTrainReservation(); 0019 0020 var cell = tab.firstChild; 0021 var date = bookingYear + cell.recursiveContent; 0022 cell = cell.nextSibling; 0023 res.reservationFor.trainNumber = cell.recursiveContent; 0024 cell = cell.nextSibling; 0025 res.reservationFor.trainName = cell.recursiveContent; 0026 cell = cell.nextSibling; 0027 res.reservationFor.departureStation.name = cell.recursiveContent; 0028 res.reservationFor.departureStation.address.addressCountry = "KR"; // Korail only serves Korea 0029 cell = cell.nextSibling; 0030 res.reservationFor.departureTime = JsonLd.toDateTime(date + " " + cell.recursiveContent, "yyyy년M월d일 hh:mm", "kr"); 0031 cell = cell.nextSibling; 0032 res.reservationFor.arrivalStation.name = cell.recursiveContent; 0033 res.reservationFor.arrivalStation.address.addressCountry = "KR"; 0034 cell = cell.nextSibling; 0035 res.reservationFor.arrivalTime = JsonLd.toDateTime(date + " " + cell.recursiveContent, "yyyy년M월d일 hh:mm", "kr"); 0036 0037 reservations.push(res); 0038 tab = tab.nextSibling; 0039 } 0040 0041 return reservations; 0042 }