From ec4c685c43bc26552cd256d1c42661ac9cf032d7 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Mon, 26 Aug 2013 21:04:50 -0400 Subject: [PATCH] Fill paragraph of message and print how old it was. --- conky-mythtv-weather-alert.plx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/conky-mythtv-weather-alert.plx b/conky-mythtv-weather-alert.plx index 9255253..f82b88f 100755 --- a/conky-mythtv-weather-alert.plx +++ b/conky-mythtv-weather-alert.plx @@ -26,10 +26,11 @@ use Date::Manip; use utf8; use feature 'unicode_strings'; use Encode qw(encode decode); +use Text::Autoformat qw(autoformat); my $now = ParseDate("now"); -my $MYTH_PATH = shift; +my $MYTH_PATH = shift @ARGV; my($command) = $MYTH_PATH . "/mythplugins/mythweather/mythweather/scripts/us_nws/nws-alert.pl"; my %data; @@ -51,11 +52,19 @@ foreach my $location (keys %data) { die "Missing $location!" if (not defined $data{$location}{alerts}); next if $data{$location}{alerts} =~ /no\s*warning/i; print "\${color5}\${font :size=20}WEATHER ALERT:\n"; + $data{$location}{updatetime} =~ s/\s*last\s*updated?\s*(at|on)\s*//i; my $datetime = ParseDate($data{$location}{updatetime}); my $ago = Delta_Format(DateCalc($datetime, $now), 0, "%mt min"); - $ago = Delta_Format(DateCalc($datetime, $now), 0, "%st sec") - if ($ago =~ /0 minutes/); - print "\${font}As of $ago ago:\n$data{$location}{alerts}\n"; + if (defined $ago) { + $ago = Delta_Format(DateCalc($datetime, $now), 0, "%st sec") + if ($ago =~ /0 minutes/); + } else { + $ago = $data{$location}{updatetime}; + } + my $data = autoformat $data{$location}{alerts}, { justify => 'left', + fill => 70}; + print "\${font}For $data{$location}{swlocation},", + "as of $ago ago:\n$data\${color}\$hr\n"; } ###############################################################################