#!/usr/bin/env perl use strict; use warnings; use 5.020; use utf8; our $VERSION = '0.00'; use Travel::Status::DE::IRIS; use Travel::Status::DE::DBWagenreihung; my ($station, $train_number) = @ARGV; my $res = Travel::Status::DE::IRIS->new(station => $station, with_related => 1); if ($res->errstr) { say STDERR $res->errstr; exit 1; } my @trains = grep { $_->train_no eq $train_number } $res->results; if (@trains != 1) { say STDERR "Unable to find train in reported departures"; exit 1; } my $wr = Travel::Status::DE::DBWagenreihung->new( departure => $trains[0]->sched_departure, train_number => $train_number, ); for my $wagon ($wr->wagons) { printf("%s %2s", $wagon->section, $wagon->number || 'X'); if ($wagon->class_type == 12) { print(" 1/2"); } elsif ($wagon->class_type) { printf(" %d", $wagon->class_type); } print("\n"); }