diff --git a/autotests/extractordata/czechrailways/czechrailways_multileg-one-way-group.txt b/autotests/extractordata/czechrailways/czechrailways_multileg-one-way-group.txt new file mode 100644 --- /dev/null +++ b/autotests/extractordata/czechrailways/czechrailways_multileg-one-way-group.txt @@ -0,0 +1,45 @@ + JÍZDENKA A MÍSTENKA + eTiket Osob: 5 + 1154 + Z/FROM/VON @ DO/TO/NACH TŘÍDA/ + CL./KL. + 06/08 17:50 Praha hl.n. @ Jaroměř 07/08 24:00 2 + * * * @ * * * * + Přes: PhaLb,Kolín,Pard.Hl,HradKrHl Km: 143 + Rezervace (místo) + Skupinová jednosměrná (5 osob) + Cena 683 Kč +Doklad je nepřenosný a platí vždy pouze ve spojení s průkazem cestujícího, jehož jméno je uvedeno na jízdence. +Jízdu je nutno nastoupit v 1. den platnosti, nejdříve však v 17:50 hod. +Daňový doklad (informace o ceně) +Tax receipt (price information) / Rechnung (Preisinformation) +Položka Tar. cena Body Cena DPH +Jízdenka 1 683 Kč 683 Kč 10 % +Rezervace 2 0 Kč 0 Kč +Celkem 683 Kč +Datum vystavení/datum platby: 31.7.2019 21:28 Platba: KARTOU/CC +Prodejce: České dráhy, a.s. 30000 Číslo obj.: 39921 835 00 +Praha 1, Nábřeží L.Svobody 1222, PSČ 110 15 DIČ: CZ70994226 +Jízdní řád a rezervace +Timetable and Reservations / Fahrplan und Reservierung +Stanice Odj. / Příj. x w Místo / Seat / Sitzplatz +Praha hl.n. 06.08. 17:50 EC 283 258 41, 42, 44 - 46 +Pardubice hl.n. 06.08. 18:46 +Ref: 544265457956, 545265457957, 547265457959, 548265457960, 540265457961 Údaje pro kontrolu + Control data +Pardubice hl.n. 06.08. 19:03 R 1262 1 21 - 24, 28 + Doklad číslo / Document no.: +Hradec Králové hl.n. 06.08. 19:23 +Ref: 541265457962 + *9-2144-549 + Jméno / Name: +Hradec Králové hl.n. 06.08. 19:33 Bus 501262 + Daniel Vrátil +Jaroměř 06.08. 19:54 + Kód transakce / Transaction code: + XUBC00 +Jízdní řád má pouze informativní charakter. + Kód nepřehýbejte! / Do not fold the barcode! + Barcode nicht knicken! +Reklama +České dráhy. Lepší cesta každý den. Strana 1/1 diff --git a/autotests/extractordata/czechrailways/czechrailways_multileg-one-way-group.txt.json b/autotests/extractordata/czechrailways/czechrailways_multileg-one-way-group.txt.json new file mode 100644 --- /dev/null +++ b/autotests/extractordata/czechrailways/czechrailways_multileg-one-way-group.txt.json @@ -0,0 +1,75 @@ +[ + { + "@context": "http://schema.org", + "@type": "TrainReservation", + "reservationFor": { + "@type": "TrainTrip", + "arrivalStation": { + "@type": "TrainStation", + "name": "Pardubice hl.n." + }, + "arrivalTime": "2019-08-06T18:46:00", + "departureDay": "2019-08-06", + "departureStation": { + "@type": "TrainStation", + "name": "Praha hl.n." + }, + "departureTime": "2019-08-06T17:50:00", + "trainNumber": "EC 283" + }, + "reservedTicket": { + "@type": "Ticket", + "ticketedSeat": { + "@type": "Seat", + "seatNumber": "41", + "seatSection": "258" + } + } + }, + { + "@context": "http://schema.org", + "@type": "TrainReservation", + "reservationFor": { + "@type": "TrainTrip", + "arrivalStation": { + "@type": "TrainStation", + "name": "Hradec Králové hl.n." + }, + "arrivalTime": "2019-08-06T19:23:00", + "departureDay": "2019-08-06", + "departureStation": { + "@type": "TrainStation", + "name": "Pardubice hl.n." + }, + "departureTime": "2019-08-06T19:03:00", + "trainNumber": "R 1262" + }, + "reservedTicket": { + "@type": "Ticket", + "ticketedSeat": { + "@type": "Seat", + "seatNumber": "21", + "seatSection": "1" + } + } + }, + { + "@context": "http://schema.org", + "@type": "TrainReservation", + "reservationFor": { + "@type": "TrainTrip", + "arrivalStation": { + "@type": "TrainStation", + "name": "Jaroměř" + }, + "arrivalTime": "2019-08-06T19:54:00", + "departureDay": "2019-08-06", + "departureStation": { + "@type": "TrainStation", + "name": "Hradec Králové hl.n." + }, + "departureTime": "2019-08-06T19:33:00", + "trainNumber": "Bus 501262" + } + } +] diff --git a/src/extractors/czechrailways.js b/src/extractors/czechrailways.js --- a/src/extractors/czechrailways.js +++ b/src/extractors/czechrailways.js @@ -101,6 +101,14 @@ } } +function findNextStationLineIndex(lines, start) { + var pos = start; + while (pos < lines.length && (lines[pos].startsWith(" ") || lines[pos].startsWith("Ref:"))) { + pos += 1; + } + return pos; +} + function parseLegs(text, purchaseDate) { var reservations = new Array(); var lines = text.split('\n'); @@ -113,14 +121,12 @@ var res = JsonLd.newObject("TrainReservation"); res.reservationFor = JsonLd.newObject("TrainTrip"); - arrIdx = depIdx + 1; + arrIdx = findNextStationLineIndex(lines, depIdx + 1) parseDeparture(res, lines[depIdx], purchaseDate); parseArrival(res, lines[arrIdx], purchaseDate); - depIdx = arrIdx + 1; + // Find the next leg - while (lines[depIdx].startsWith(" ")) { - depIdx += 1; - } + depIdx = findNextStationLineIndex(lines, arrIdx + 1); reservations.push(res); }