diff options
-rwxr-xr-x | bin/db-wagenreihung-to-json | 23 |
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 |