diff options
Diffstat (limited to 'bin/laptop/weather')
-rwxr-xr-x | bin/laptop/weather | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/bin/laptop/weather b/bin/laptop/weather new file mode 100755 index 0000000..a0a9d14 --- /dev/null +++ b/bin/laptop/weather @@ -0,0 +1,60 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; + +use open ':encoding(UTF-8)', ':std'; + +use DateTime; +use Path::Class; +use WWW::Wunderground::API; + +chomp(my $api_key = file("$ENV{HOME}/.wunderground")->slurp); + +my %weather_pics = ( + 'Thunderstorm' => "\x{26a1}", + 'Rain' => "\x{2614}", + 'Drizzle' => "\x{2614}", + 'Showers' => "\x{2614}", + 'Cloudy' => "\x{2601}", + 'Clouds' => "\x{2601}", + 'Overcast' => "\x{2601}", + 'Fog' => "\x{2592}", + 'Mist' => "\x{2592}", + 'Haze' => "\x{2592}", + 'Clear' => "\x{2600}", + 'Pellets' => "\x{2744}", + 'Snow' => "\x{2744}", +); + +my $wu = WWW::Wunderground::API->new( + location => '10012', + auto_api => 1, + api_key => $api_key, +); + +my $forecast = $wu->forecast->simpleforecast->forecastday->[0]; +my $conditions = $wu->conditions; + +my $temp = int($conditions->temp_f); +my $high = $forecast->{high}{fahrenheit}; +my $low = $forecast->{low}{fahrenheit}; +my $feelslike = int($conditions->feelslike_f); +my $precip = $forecast->{pop}; + +(my $description = $conditions->weather) =~ s/.* //; +my $weather = $weather_pics{$description} // $description; + +my $time = DateTime->now(time_zone => 'local'); + +say join(' ', + "$precip%", + $weather, + "${temp}F", + (($feelslike != $temp) + ? ("(\x{2245}${feelslike}F)") + : ()), + (($time->hour > 16 || $time->hour <= 4) + ? ("\x{2193}${low}F") + : ("\x{2191}${high}F")), +); |