diff options
author | dakkar <dakkar@thenautilus.net> | 2013-05-27 16:40:18 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2013-05-27 16:40:18 +0100 |
commit | 2cbf023942b42d798d73b5ce85b20ddadacc6cec (patch) | |
tree | 3ba85682364b48d2dd72d8a37b57b1b204be7fcf | |
parent | kill debug Data::Printer (diff) | |
download | HomePanel-2cbf023942b42d798d73b5ce85b20ddadacc6cec.tar.gz HomePanel-2cbf023942b42d798d73b5ce85b20ddadacc6cec.tar.bz2 HomePanel-2cbf023942b42d798d73b5ce85b20ddadacc6cec.zip |
include busses in html
-rw-r--r-- | driver.pl | 26 | ||||
-rw-r--r-- | forecast.html.tt | 144 | ||||
-rw-r--r-- | lib/HomePanel/Render.pm | 78 |
3 files changed, 185 insertions, 63 deletions
diff --git a/driver.pl b/driver.pl new file mode 100644 index 0000000..dacda01 --- /dev/null +++ b/driver.pl @@ -0,0 +1,26 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.014; +use WebService::ForecastIo::Response; +use TFL::Bus; +use HomePanel::Render; +use Path::Class; + +my $forecast = WebService::ForecastIo::Response->new( + file($ARGV[0])->slurp(iomode=>'<:raw') +); +my $bus = TFL::Bus->new()->request(TFL::Bus::Request->new({ + StopPointName => 'Hotspur Road', + #Towards => 'Islip Manor', + ReturnList => [qw(StopID StopCode1 VisitNumber TripID VehicleID LineID LineName DirectionID DestinationText DestinationName EstimatedTime)], +})); +my $template = file(__FILE__)->parent->file('forecast.html.tt'); + +print + HomePanel::Render->new({ + template_file => $template, + forecast => $forecast, + bus => $bus, + tube => '', + })->render; diff --git a/forecast.html.tt b/forecast.html.tt index d45e2db..a3cb750 100644 --- a/forecast.html.tt +++ b/forecast.html.tt @@ -46,74 +46,92 @@ </style> </head> <body> - <div class="currently"> - <h2>Currently</h2> - <span class="icon"><img src="[% icon_for(cur.icon) %]" alt="[% cur.icon %]" /></span> - <dl class="currently"> - <dt class="temperature">Temperature:</dt> - <dd class="temperature">[% cur.temperature %]°</dd> - <dt class="summary">Summary:</dt> - <dd class="summary">[% cur.summary %]</dd> - </dl> - </div> - <div class="next-hour"> - <h2>Next hour</h2> - <span class="icon"><img src="[% icon_for(f.minutely.icon) %]" alt="[% f.minutely.icon %]" /></span> - <dl class="next-hour"> - <dt class="summary">Summary:</dt> - <dd class="summary">[% f.minutely.summary %]</dd> - </dl> - </div> - <div class="next-day"> - <h2>Next 24 hours</h2> - <span class="icon"><img src="[% icon_for(hourly.icon) %]" alt="[% hourly.icon %]" /></span> - <dl class="next-day"> - <dt class="summary">Summary:</dt> - <dd class="summary">[% hourly.summary %]</dd> - </dl> - </div> - <div class="next-week"> - <h2>Next 7 days</h2> - <span class="icon"><img src="[% icon_for(f.daily.icon) %]" alt="[% f.daily.icon %]" /></span> - <dl class="next-week"> - <dt class="summary">Summary:</dt> - <dd class="summary">[% f.daily.summary %]</dd> - </dl> - </div> - <div class="days"> - <div class="day today"> - <span class="icon"><img src="[% icon_for(today.icon) %]" alt="[% today.icon %]" /></span> - <dl class="today"> + <div class="forecast"> + <div class="currently"> + <h2>Currently</h2> + <span class="icon"><img src="[% icon_for(cur.icon) %]" alt="[% cur.icon %]" /></span> + <dl class="currently"> + <dt class="temperature">Temperature:</dt> + <dd class="temperature">[% cur.temperature %]°</dd> <dt class="summary">Summary:</dt> - <dd class="summary">[% today.summary %]</dd> - <dt class="temperature min">Min temperature:</dt> - <dd class="temperature min">[% today.temperatureMin %]° <span class="time">[% time(today.temperatureMinTime) %]</span></dd> - <dt class="temperature max">Max temperature:</dt> - <dd class="temperature max">[% today.temperatureMax %]° <span class="time">[% time(today.temperatureMaxTime) %]</span></dd> - <dt class="sunrise">Sunrise:</dt> - <dd class="sunrise"><span class="time">[% time(today.sunriseTime) %]</span></dd> - <dt class="sunset">Sunset:</dt> - <dd class="sunset"><span class="time">[% time(today.sunsetTime) %]</span></dd> + <dd class="summary">[% cur.summary %]</dd> </dl> - <div class="timeline"> - <div class="summary"> - [% left=0 ;FOR span IN hourly.spans_by_string('summary'); - width=3*hours_length(span) %] - <span class="stripes" style="width: [% width %]em; left: [% left %]em"><span>[% span.value %]</span></span> - [% left=left+width; END %] - </div> - <div class="hours"> - [% left=0; FOR h IN hourly.data; BREAK IF loop.last %] - <span class="stripes" style="width: 3em; left: [% left %]em"><span>[% time(h.time) %]</span></span> - [% left=left+3; END %] - </div> - <div class="temperature"> - [% left=0; FOR h IN hourly.data; BREAK IF loop.last %] - <span class="stripes" style="width: 3em; left: [% left %]em"><span>[% h.temperature %]°</span></span> - [% left=left+3; END %] + </div> + <div class="next-hour"> + <h2>Next hour</h2> + <span class="icon"><img src="[% icon_for(f.minutely.icon) %]" alt="[% f.minutely.icon %]" /></span> + <dl class="next-hour"> + <dt class="summary">Summary:</dt> + <dd class="summary">[% f.minutely.summary %]</dd> + </dl> + </div> + <div class="next-day"> + <h2>Next 24 hours</h2> + <span class="icon"><img src="[% icon_for(hourly.icon) %]" alt="[% hourly.icon %]" /></span> + <dl class="next-day"> + <dt class="summary">Summary:</dt> + <dd class="summary">[% hourly.summary %]</dd> + </dl> + </div> + <div class="next-week"> + <h2>Next 7 days</h2> + <span class="icon"><img src="[% icon_for(f.daily.icon) %]" alt="[% f.daily.icon %]" /></span> + <dl class="next-week"> + <dt class="summary">Summary:</dt> + <dd class="summary">[% f.daily.summary %]</dd> + </dl> + </div> + <div class="days"> + <div class="day today"> + <span class="icon"><img src="[% icon_for(today.icon) %]" alt="[% today.icon %]" /></span> + <dl class="today"> + <dt class="summary">Summary:</dt> + <dd class="summary">[% today.summary %]</dd> + <dt class="temperature min">Min temperature:</dt> + <dd class="temperature min">[% today.temperatureMin %]° <span class="time">[% time(today.temperatureMinTime) %]</span></dd> + <dt class="temperature max">Max temperature:</dt> + <dd class="temperature max">[% today.temperatureMax %]° <span class="time">[% time(today.temperatureMaxTime) %]</span></dd> + <dt class="sunrise">Sunrise:</dt> + <dd class="sunrise"><span class="time">[% time(today.sunriseTime) %]</span></dd> + <dt class="sunset">Sunset:</dt> + <dd class="sunset"><span class="time">[% time(today.sunsetTime) %]</span></dd> + </dl> + <div class="timeline"> + <div class="summary"> + [% left=0 ;FOR span IN hourly.spans_by_string('summary'); + width=3*hours_length(span) %] + <span class="stripes" style="width: [% width %]em; left: [% left %]em"><span>[% span.value %]</span></span> + [% left=left+width; END %] + </div> + <div class="hours"> + [% left=0; FOR h IN hourly.data; BREAK IF loop.last %] + <span class="stripes" style="width: 3em; left: [% left %]em"><span>[% time(h.time) %]</span></span> + [% left=left+3; END %] + </div> + <div class="temperature"> + [% left=0; FOR h IN hourly.data; BREAK IF loop.last %] + <span class="stripes" style="width: 3em; left: [% left %]em"><span>[% h.temperature %]°</span></span> + [% left=left+3; END %] + </div> </div> </div> </div> </div> + <div class="bus"> + <table class="prediction"> + <thead> + <tr><th>Line</th><th>Destination</th><th>When</th></tr> + </thead> + <tbody> + [% FOREACH p IN b.Prediction %] + <tr> + <td>[% p.LineName %]</td> + <td>[% p.DestinationText %]</td> + <td>[% p.EstimatedTime %]</td> + </tr> + [% END %] + </tbody> + </table> + </div> </body> </html> diff --git a/lib/HomePanel/Render.pm b/lib/HomePanel/Render.pm new file mode 100644 index 0000000..a1bbcc9 --- /dev/null +++ b/lib/HomePanel/Render.pm @@ -0,0 +1,78 @@ +package HomePanel::Render; +use Moose; +use MooseX::Types::Path::Class; +use Template::Provider::Encoding; +use Template::Stash::ForceUTF8; +use Template; + +has [qw(provider stash template)] => ( + is => 'ro', + lazy_build => 1, +); +sub _build_provider { + Template::Provider::Encoding->new( + ABSOLUTE => 1, + RELATIVE => 1, + ); +} +sub _build_stash { + Template::Stash::ForceUTF8->new; +} +sub _build_template { + my ($self) = @_; + Template->new( + LOAD_TEMPLATES => [ $self->provider ], + STASH => $self->stash + ); +} + +has template_file => ( + is => 'ro', + isa => 'Path::Class::File', + coerce => 1, + required => 1, +); + +has [qw(forecast bus tube)] => ( + is => 'ro', + required => 1, +); + +{ +my %icon_for=( + 'clear-day' => '2', + 'clear-night' => '3', + rain => '18', + snow => '23', + sleet => '24', + wind => '6', + fog => '13', + cloudy => '14', + 'partly-cloudy-day' => '8', + 'partly-cloudy-night' => '9', +); +sub icon_for { + my ($status) = @_; + + return "icons/".($icon_for{$status}//'45').".svg"; +} +} + +sub render { + my ($self) = @_; + + my $output; + + $self->template->process( + $self->template_file->stringify, + { + f => $self->forecast, + b => $self->bus, + t => $self->tube, + icon_for => \&icon_for, + }, + \$output, + ) or die $self->template->error; + + return $output; +} |