#!/usr/bin/env perl use strict; use warnings; use 5.010; our $VERSION = '1.05'; use Getopt::Long qw(:config no_ignore_case); use List::MoreUtils qw(uniq); use List::Util qw(first max); use Travel::Status::DE::HAFAS; my %train_type; my ( $date, $time ); my $arrivals = 0; my $ignore_late = 0; my $types = q{}; my $language; my $developer_mode; my ( $list_services, $service, $hafas_url ); my @excluded_mots; my @output; binmode( STDOUT, ':encoding(utf-8)' ); GetOptions( 'a|arrivals' => \$arrivals, 'd|date=s' => \$date, 'h|help' => sub { show_help(0) }, 'l|lang=s' => \$language, 'L|ignore-late' => \$ignore_late, 'm|mot=s' => \$types, 's|service=s' => \$service, 't|time=s' => \$time, 'u|url=s' => \$hafas_url, 'V|version' => \&show_version, 'devmode' => \$developer_mode, 'list' => \$list_services, ) or show_help(1); if ($list_services) { printf( "%-40s %-14s %s\n\n", 'operator', 'abbr. (-s)', 'url (-u)' ); for my $service ( Travel::Status::DE::HAFAS::get_services() ) { printf( "%-40s %-14s %s\n", @{$service}{qw(name shortname url)} ); } exit 0; } for my $type ( split( qr{,}, $types ) ) { if ( substr( $type, 0, 1 ) eq q{!} ) { $train_type{ substr( $type, 1 ) } = 0; push( @excluded_mots, substr( $type, 1 ) ); } else { $train_type{$type} = 1; } } if ( $train_type{help} or $train_type{list} or $train_type{'?'} ) { my @mots = @{ Travel::Status::DE::HAFAS::get_service($service)->{productbits} }; @mots = grep { $_ ne 'x' } @mots; @mots = uniq @mots; @mots = sort @mots; say join( "\n", @mots ); exit 0; } my $status = Travel::Status::DE::HAFAS->new( date => $date, language => $language, excluded_mots => \@excluded_mots, station => shift || show_help(1), time => $time, mode => $arrivals ? 'arr' : 'dep', developer_mode => $developer_mode, service => $service, url => $hafas_url, ); sub show_help { my ($code) = @_; print 'Usage: hafas-m [-d ] [-m ] [-t