From 2cbf023942b42d798d73b5ce85b20ddadacc6cec Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 27 May 2013 16:40:18 +0100 Subject: include busses in html --- driver.pl | 26 +++++++++ forecast.html.tt | 144 +++++++++++++++++++++++++++--------------------- lib/HomePanel/Render.pm | 78 ++++++++++++++++++++++++++ 3 files changed, 185 insertions(+), 63 deletions(-) create mode 100644 driver.pl create mode 100644 lib/HomePanel/Render.pm 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 @@ -
-

Currently

- [% cur.icon %] -
-
Temperature:
-
[% cur.temperature %]°
-
Summary:
-
[% cur.summary %]
-
-
-
-

Next hour

- [% f.minutely.icon %] -
-
Summary:
-
[% f.minutely.summary %]
-
-
-
-

Next 24 hours

- [% hourly.icon %] -
-
Summary:
-
[% hourly.summary %]
-
-
-
-

Next 7 days

- [% f.daily.icon %] -
-
Summary:
-
[% f.daily.summary %]
-
-
-
-
- [% today.icon %] -
+
+
+

Currently

+ [% cur.icon %] +
+
Temperature:
+
[% cur.temperature %]°
Summary:
-
[% today.summary %]
-
Min temperature:
-
[% today.temperatureMin %]° [% time(today.temperatureMinTime) %]
-
Max temperature:
-
[% today.temperatureMax %]° [% time(today.temperatureMaxTime) %]
-
Sunrise:
-
[% time(today.sunriseTime) %]
-
Sunset:
-
[% time(today.sunsetTime) %]
+
[% cur.summary %]
-
-
- [% left=0 ;FOR span IN hourly.spans_by_string('summary'); - width=3*hours_length(span) %] - [% span.value %] - [% left=left+width; END %] -
-
- [% left=0; FOR h IN hourly.data; BREAK IF loop.last %] - [% time(h.time) %] - [% left=left+3; END %] -
-
- [% left=0; FOR h IN hourly.data; BREAK IF loop.last %] - [% h.temperature %]° - [% left=left+3; END %] +
+
+

Next hour

+ [% f.minutely.icon %] +
+
Summary:
+
[% f.minutely.summary %]
+
+
+
+

Next 24 hours

+ [% hourly.icon %] +
+
Summary:
+
[% hourly.summary %]
+
+
+
+

Next 7 days

+ [% f.daily.icon %] +
+
Summary:
+
[% f.daily.summary %]
+
+
+
+
+ [% today.icon %] +
+
Summary:
+
[% today.summary %]
+
Min temperature:
+
[% today.temperatureMin %]° [% time(today.temperatureMinTime) %]
+
Max temperature:
+
[% today.temperatureMax %]° [% time(today.temperatureMaxTime) %]
+
Sunrise:
+
[% time(today.sunriseTime) %]
+
Sunset:
+
[% time(today.sunsetTime) %]
+
+
+
+ [% left=0 ;FOR span IN hourly.spans_by_string('summary'); + width=3*hours_length(span) %] + [% span.value %] + [% left=left+width; END %] +
+
+ [% left=0; FOR h IN hourly.data; BREAK IF loop.last %] + [% time(h.time) %] + [% left=left+3; END %] +
+
+ [% left=0; FOR h IN hourly.data; BREAK IF loop.last %] + [% h.temperature %]° + [% left=left+3; END %] +
+
+ + + + + + [% FOREACH p IN b.Prediction %] + + + + + + [% END %] + +
LineDestinationWhen
[% p.LineName %][% p.DestinationText %][% p.EstimatedTime %]
+
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; +} -- cgit v1.2.3