File indexing completed on 2024-12-29 04:51:03

0001 /*
0002   SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003   SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 function parseReservation(html, node)
0007 {
0008     const text = html.root.recursiveContent;
0009     const resNum = text.match(/予約番号\n(.*)\n/);
0010     const date = text.match(/乗車日.*?(\d.*)\n/);
0011     const trainInfo = text.match(/列車情報==([\s\S]*?)==/)[1];
0012     const legs = trainInfo.split(/\(\d列車目\)\n/);
0013     var qrCode = undefined;
0014     for (qrCodeNode of node.findChildNodes({ mimeType: "text/plain", scope: "Descendants" })) {
0015         if (qrCodeNode.location == "qrcode") {
0016             qrCode = qrCodeNode.content;
0017             break;
0018         }
0019     }
0020 
0021     var reservations = new Array();
0022     for (leg of legs) {
0023         const fromTo = leg.match(/区 間:(.*?)\((.*?)\)→(.*?)\((.*?)\)\n/);
0024         if (!fromTo) {
0025             continue;
0026         }
0027         var res = JsonLd.newTrainReservation();
0028         res.reservationFor.departureStation.name = fromTo[1];
0029         res.reservationFor.departureStation.address.addressCountry = 'JP';
0030         res.reservationFor.departureTime = JsonLd.toDateTime(date[1] + fromTo[2], 'yyyy年MM月dd日hh時mm分', 'jp');
0031         res.reservationFor.arrivalStation.name = fromTo[3];
0032         res.reservationFor.arrivalStation.address.addressCountry = 'JP';
0033         res.reservationFor.arrivalTime = JsonLd.toDateTime(date[1] + fromTo[4], 'yyyy年MM月dd日hh時mm分', 'jp');
0034 
0035         const trainName = leg.match(/列車名:(.*)\n/);
0036         res.reservationFor.trainName = trainName[1];
0037 
0038         const seat = leg.match(/座 席:(.*号車)(.*)\n/);
0039         if (seat) {
0040             res.reservedTicket.ticketedSeat.seatSection = seat[1];
0041             res.reservedTicket.ticketedSeat.seatNumber = seat[2];
0042         }
0043 
0044         res.reservationNumber = resNum[1];
0045         if (qrCode) {
0046             res.reservedTicket.ticketToken = "qrCode:" + qrCode;
0047         }
0048         reservations.push(res);
0049     }
0050     return reservations;
0051 }