summaryrefslogtreecommitdiff
path: root/forecast-file.pl
diff options
context:
space:
mode:
Diffstat (limited to 'forecast-file.pl')
-rw-r--r--forecast-file.pl40
1 files changed, 37 insertions, 3 deletions
diff --git a/forecast-file.pl b/forecast-file.pl
index 990dfa9..02dba1c 100644
--- a/forecast-file.pl
+++ b/forecast-file.pl
@@ -4,11 +4,45 @@ use warnings;
use 5.014;
use WebService::ForecastIo::Response;
use Path::Class;
+use Template::Provider::Encoding;
+use Template::Stash::ForceUTF8;
use Template;
-my $res = WebService::ForecastIo::Response->new(file($ARGV[0])->slurp);
-my $t = Template->new;
-$t->process(\*DATA,{f=>$res})
+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";
+}
+
+my $res = WebService::ForecastIo::Response->new(
+ file($ARGV[0])->slurp(iomode=>'<:raw')
+);
+my $tf = file(__FILE__)->parent->file('forecast.html.tt');
+my $t = Template->new(
+ LOAD_TEMPLATES => [ Template::Provider::Encoding->new(
+ ABSOLUTE => 1,
+ RELATIVE => 1,
+ ) ],
+ STASH => Template::Stash::ForceUTF8->new,
+);
+binmode STDOUT,':utf8';
+$t->process($tf->stringify,{
+ f => $res,
+ icon_for => \&icon_for,
+})
or die $t->error;
__DATA__