Commit 4bce052b authored by Volker Krause's avatar Volker Krause
Browse files

Extract station identifiers from Thalys barcodes

Also, decode the country code in there in post-processing.
parent b839e209
......@@ -234,6 +234,8 @@ TrainStation ExtractorPostprocessorPrivate::processTrainStation(TrainStation sta
} else if (id.startsWith(QLatin1String("ir:")) && id.size() > 4) {
const auto record = KnowledgeDb::stationForIndianRailwaysStationCode(id.mid(3));
applyStationData(record, station);
} else if (id.startsWith(QLatin1String("benerail:")) && id.size() == 14) {
applyStationCountry(id.mid(9, 2).toUpper(), station);
}
return processPlace(station);
......
......@@ -15,6 +15,16 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// see https://community.kde.org/KDE_PIM/KItinerary/Thalys_Barcode
function readEncodedString(bitArray, startIdx, size)
{
var id = "";
for (var i = 0; i < size; ++i) {
id += String.fromCharCode(bitArray.readNumberMSB(startIdx + i * 6, 6) + 32);
}
return id;
}
function parseReservation(html) {
var res = JsonLd.newTrainReservation();
......@@ -46,5 +56,9 @@ function parseReservation(html) {
var name = passengerElem.recursiveContent.match(/\n(.*)/);
res.underName.name = name[1];
var bitArray = Barcode.toBitArray(Barcode.fromBase64(token[1]));
res.reservationFor.departureStation.identifier = "benerail:" + readEncodedString(bitArray, 18 * 8 + 4, 5);
res.reservationFor.arrivalStation.identifier = "benerail:" + readEncodedString(bitArray, 22 * 8 + 2, 5);
return res;
}
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