-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddb
59 lines (50 loc) · 1.65 KB
/
ddb
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /usr/bin/perl
use warnings;
use strict;
use GBTrains::Schema;
use DateTime::Format::ISO8601;
my $date = @ARGV > 1 ?
DateTime::Format::ISO8601->parse_datetime($ARGV[1], 'YYMMDD') :
DateTime->today;
my $sch = GBTrains::Schema->connect("dbi:SQLite:dbname=mca.sqlite");
if ($ARGV[0] =~ /^[A-Z]\d\d\d\d\d$/) {
for my $train ($sch->resultset('bs')->search({unique_id => $ARGV[0]})) {
if ($train->runs_on($date)) {
for my $cr ($train->crs) {
printf("%4s:\n", $cr->train_identity);
for my $li ($cr->lis) {
no warnings qw/uninitialized/;
printf("%26s %4s %4s %s\n", $li->ti->tps_descr,
$li->public_arr_time, $li->public_dep_time,
$li->activity);
}
}
}
}
} else {
my $loc;
if ($ARGV[0] =~ /^[A-Z]{3}$/) {
$loc = $sch->resultset('ti')->find({crs_code => $ARGV[0]});
} else {
$loc = $sch->resultset('ti')->find($ARGV[0]);
}
defined $loc or die "Station '$ARGV[0]' not found.\n";
printf "Dead departure board for %s on %s\n", $loc->tps_descr, $date->ymd;
for my $li ($loc->lis([{ public_dep_time => { '!=' => '0000' } },
{ public_arr_time => { '!=' => '0000' } },],
{order_by =>
q{coalesce(nullif(public_dep_time, '0000'),
nullif(public_arr_time, '0000'))},
prefetch => {cr => 'bs'}})) {
next unless $li->cr->bs->runs_on($date);
no warnings qw/uninitialized/;
my $lo = $li->cr->bs->lo;
my $lt = $li->cr->bs->lt;
printf "%5s/%4s: %26s %4s %3s %4s %-26s\n",
$li->cr->bs->unique_id,
$li->cr->train_identity,
$lo->id eq $li->id ? '' : $lo->ti->tps_descr,
$li->public_arr_time, $li->platform, $li->public_dep_time,
$lt->id eq $li->id ? '' : $lt->ti->tps_descr,
}
}