summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-08-27 02:58:16 -0400
committerJesse Luehrs <doy@tozt.net>2013-08-27 03:08:22 -0400
commit84d9f252092e05743be1efc4e9062509d30adb55 (patch)
treeee45beee86dfdb68bd61167f7573af1babb49bbf
parent785a9b5882f8767bae7e9059f18591b1dd6719c9 (diff)
downloadconf-84d9f252092e05743be1efc4e9062509d30adb55.tar.gz
conf-84d9f252092e05743be1efc4e9062509d30adb55.zip
script for getting the current weather
-rwxr-xr-xbin/weather51
1 files changed, 51 insertions, 0 deletions
diff --git a/bin/weather b/bin/weather
new file mode 100755
index 0000000..2488896
--- /dev/null
+++ b/bin/weather
@@ -0,0 +1,51 @@
+#!/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}",
+ 'Partly Cloudy' => "\x{2601}",
+ 'Scattered Clouds' => "\x{2601}",
+ 'Overcast' => "\x{2601}",
+ 'Clear' => "\x{2600}",
+);
+
+my $wu = WWW::Wunderground::API->new(
+ location => 'Providence, RI',
+ 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 $weather = $weather_pics{$conditions->weather};
+
+my $time = DateTime->now(time_zone => 'local');
+
+say join(' ',
+ "$precip%",
+ $weather,
+ "${temp}F",
+ (($feelslike != $temp)
+ ? ("(\x{2252}${feelslike}F)")
+ : ()),
+ (($time->hour > 16 || $time->hour < 4)
+ ? ("\x{2193}${low}F")
+ : ("\x{2191}${high}F")),
+);