blob: 11f69a52e64eb53117fc5ec852b77badc1670d12 (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#!/usr/bin/env perl
use Mojolicious::Lite;
use File::ShareDir qw(dist_file);
use HTML::Template;
use Travel::Status::DE::DeutscheBahn;
get '/' => sub {
my $self = shift;
my $station = $self->param('station');
if ( not $station ) {
return $self->render;
}
$self->redirect_to("/multi/${station}");
} => 'index';
get '/multi/:station' => sub {
my $self = shift;
my $station = $self->stash('station');
my @params;
my $status = Travel::Status::DE::DeutscheBahn->new( station => $station );
my $template = HTML::Template->new(
filename => dist_file( 'db-fakedisplay', 'multi-lcd.html' ),
loop_context_vars => 1,
);
for my $result ( $status->results ) {
push(
@params,
{
time => $result->time,
train => $result->train,
via => [ map { { stop => $_ } } $result->route_interesting(3) ],
destination => $result->destination,
platform => ( split( / /, $result->platform ) )[0],
info => $result->info,
}
);
}
$template->param( departures => \@params );
$self->render( text => $template->output );
};
app->start();
__DATA__
@@ index.html.ep
% title 'DB Fakedisplay';
<% if (my $error = flash 'error' ) { %>
Error: <%= $error %><br/>
<% } %>
<%= form_for index => begin %>
Stop:<br/>
<%= text_field 'station' %><br/>
<%= submit_button 'Display' %>
<% end %>
|