summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-12-12 06:40:26 +0100
committerDaniel Friesel <derf@finalrewind.org>2020-12-12 06:40:26 +0100
commit81518df3de1c46d5af9990ff3445fe3bb1267515 (patch)
tree100be65bb96a9dd16b7d53e93c4695da29256e19
parent75d57df48e8d9ca8577e04671fe95e607f1d6e74 (diff)
add train route
-rwxr-xr-xbin/db-wagenreihung-to-json23
1 files changed, 22 insertions, 1 deletions
diff --git a/bin/db-wagenreihung-to-json b/bin/db-wagenreihung-to-json
index 9d7cc73..09027ab 100755
--- a/bin/db-wagenreihung-to-json
+++ b/bin/db-wagenreihung-to-json
@@ -41,7 +41,8 @@ my $command = [ "pdftotext", "-layout", "-nopgbrk", $wr_pdf, "/dev/stdout" ];
# stdin: /dev/null
# stdout: $wr_txt
# stderr: forwarded to terminal
-run3( $command, \undef, \$wr_txt, undef );
+run3( $command, \undef, \$wr_txt, undef,
+ { binmode_stdout => ':encoding(utf-8)' } );
if ($?) {
my $exit_status = $? >> 8;
@@ -56,6 +57,8 @@ my ( $type, $number );
my %map;
my %wagon_map;
+my $state = "";
+
for my $line (@lines) {
if ( $line
@@ -70,6 +73,8 @@ for my $line (@lines) {
next;
}
+ $state = "train_no";
+
#say "$type $number";
$map{$number} = {
raw => $type,
@@ -114,6 +119,12 @@ for my $line (@lines) {
# LPFT-T: ICE BR 411 / 415 / 605
# LPFT-W: ICE BR 403 / 406
$number = undef;
+ $state = "";
+ }
+
+ elsif ( $state eq "train_no" and $line =~ m{ ^ \s{5} \S }x ) {
+ $state = "route";
+ $map{$number}{route} = "";
}
# ICE types can be further distinguished by rolling stock. For instance,
@@ -154,6 +165,16 @@ for my $line (@lines) {
}
}
+ if ( $state eq "route" and $line =~ m{ ^ \s{5} (?<route> .* ) $ }x ) {
+ if ( length( $map{$number}{route} ) ) {
+ $map{$number}{route} .= ' ';
+ }
+ $map{$number}{route} .= $+{route};
+ }
+ elsif ( $state eq "route" and $line eq "" ) {
+ $state = "details";
+ }
+
if ( $number
and $line
=~ m{ ^ \d* \s{1,10} (?<type> D? (A|AB|B|W) R? D? [aeimpvw] \S* ) \s* (?<number> \d+ )? (?: $ | \s{6} ) }x