#!/usr/bin/env perl use Mojolicious::Lite; use Cache::File; use File::ShareDir qw(dist_file); use HTML::Template; use Travel::Status::DE::DeutscheBahn; our $VERSION = '0.00'; sub get_results_for { my ($station) = @_; my $cache = Cache::File->new( cache_root => '/tmp/db-fake', default_expires => '900 sec' ); my $results = $cache->thaw($station); if ( not $results ) { my $status = Travel::Status::DE::DeutscheBahn->new( station => $station ); $results = [ $status->results ]; $cache->freeze( $station, $results ); } return @{$results}; } get '/' => sub { my $self = shift; my $station = $self->param('station'); if ( not $station ) { return $self->render; } $self->redirect_to("/${station}"); } => 'index'; get '/:station' => sub { my $self = shift; my $station = $self->stash('station'); my @params; my $template = HTML::Template->new( filename => dist_file( 'db-fakedisplay', 'multi-lcd.html' ), loop_context_vars => 1, ); my @results = get_results_for($station); if ( not @results ) { $self->render( 'index', error => "Got no results for '$station'", ); return; } for my $result (@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, version => $VERSION ); $self->render( text => $template->output ); }; get '/multi/:station' => sub { my $self = shift; my $station = $self->stash('station'); $self->redirect_to("/${station}"); }; app->start(); __DATA__ @@ index.html.ep DB Fakedisplay

DB-Fakedisplay displays the next departures at a DB station, just like the big LC display in the station itself.

<% if (my $error = stash 'error') { %> Error: <%= $error %>
<% } %> <%= form_for index => begin %> Station name:
<%= text_field 'station' %>
<%= submit_button 'Display' %> <% end %>