summaryrefslogtreecommitdiff
path: root/bin/dbwagenreihung
blob: 1d842fa56e29827509f53e2c4958388a6cdee909 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/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");
}