diff options
author | Birte Kristina Friesel <birte.friesel@uos.de> | 2025-01-21 17:54:32 +0100 |
---|---|---|
committer | Birte Kristina Friesel <birte.friesel@uos.de> | 2025-01-21 17:54:32 +0100 |
commit | 546858a40c882261f9701f1d1d8ba4634cb52bd8 (patch) | |
tree | 1dec4e58cdbef86456e8fe1b51984a8c70b95781 /bin | |
parent | 4d617f8d10d5746c96e2db6aacc1bcbe6f0d51f3 (diff) |
dbris-m: Filter out unknown mots; do not pass them to bahn.de
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/dbris-m | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/bin/dbris-m b/bin/dbris-m index 19eb127..994f5f4 100755 --- a/bin/dbris-m +++ b/bin/dbris-m @@ -21,7 +21,8 @@ my $use_cache = 1; my $cache; my ( $json_output, $raw_json_output ); -my @output; +my %known_mot = map { $_ => 1 } + (qw(ICE EC_IC IR REGIONAL SBAHN BUS SCHIFF UBAHN TRAM ANRUFPFLICHTIG)); binmode( STDOUT, ':encoding(utf-8)' ); for my $arg (@ARGV) { @@ -156,7 +157,22 @@ if ( $mots and $mots eq 'help' ) { } if ($mots) { - $opt{modes_of_transit} = [ split( qr{, *}, $mots ) ]; + + # Passing unknown MOTs to the backend results in HTTP 422 Unprocessable Entity + my @mots = split( qr{, *}, $mots ); + my $found_unknown; + for my $mot (@mots) { + if ( not $known_mot{$mot} ) { + $found_unknown = 1; + say STDERR +"-m / --modes-of-transit: skipping unknown mode of transit '$mot'"; + } + } + if ($found_unknown) { + say STDERR 'supported modes of transit are: ' + . join( q{, }, sort keys %known_mot ); + } + $opt{modes_of_transit} = [ grep { $known_mot{$_} } @mots ]; } my $status = Travel::Status::DE::DBRIS->new(%opt); |