#!/usr/bin/env perl use strict; use warnings; use 5.010; use File::ShareDir qw(dist_file); use Getopt::Long qw(:config no_ignore_case); use HTML::Template; use List::Util qw(first); use Travel::Status::DE::DeutscheBahn; our $VERSION = '0.00'; sub show_help { my ($exit_status) = @_; say 'Usage: db-fakedisplay '; say 'See also: man db-fakedisplay'; exit $exit_status; } GetOptions( 'h|help' => sub { show_help(0) }, 'V|version' => sub { say "db-fakedisplay version ${VERSION}"; exit 0 }, ) or show_help(1); if (@ARGV < 2) { show_help(1); } my ($station, @platforms) = @ARGV; my $template_file = dist_file('db-fakedisplay', 'template.html'); my $template = HTML::Template->new( filename => $template_file); my $status = Travel::Status::DE::DeutscheBahn->new( station => $station ); my @params; for my $platform (@platforms) { my $info = first { $_->platform =~ m{ ^ $platform (?: \s | $ )}x } $status->results; if (not defined $info) { push(@params, { platform => $platform }); next; } push(@params, { time => $info->time, train => $info->train, via => [ map { { stop => $_ } } $info->route_interesting(3) ], destination => $info->destination, platform => (split(/ /, $info->platform))[0], info => $info->info, }); } $template->param( platform => \@params, ); say $template->output; __END__ =head1 NAME db-fakedisplay - Show train departures, as seen on the displays on most main stations =head1 SYNOPSIS B I I =head1 VERSION version 0.00 =head1 DESCRIPTION B outputs HTML showing the next departure for every I on I on stdout. The HTML is styled to look like the LCDs installed on most (major) stations. =head1 OPTIONS =over =item B<-V>, B<--version> Show version information =back =head1 EXIT STATUS Zero. =head1 CONFIGURATION None. =head1 DEPENDENCIES =over =item * File::ShareDir(3pm) =item * HTML::Template(3pm) =item * Travel::Status::DE::DeutscheBahn(3pm) =back =head1 BUGS AND LIMITATIONS Unknown =head1 SEE ALSO There is some example output available at L. =head1 AUTHOR Copyright (C) 2011 by Daniel Friesel Ederf@finalrewind.orgE =head1 LICENSE 0. You just DO WHAT THE FUCK YOU WANT TO.