Fill paragraph of message and print how old it was.
This commit is contained in:
parent
df202085ef
commit
ec4c685c43
1 changed files with 13 additions and 4 deletions
|
@ -26,10 +26,11 @@ use Date::Manip;
|
||||||
use utf8;
|
use utf8;
|
||||||
use feature 'unicode_strings';
|
use feature 'unicode_strings';
|
||||||
use Encode qw(encode decode);
|
use Encode qw(encode decode);
|
||||||
|
use Text::Autoformat qw(autoformat);
|
||||||
|
|
||||||
my $now = ParseDate("now");
|
my $now = ParseDate("now");
|
||||||
|
|
||||||
my $MYTH_PATH = shift;
|
my $MYTH_PATH = shift @ARGV;
|
||||||
my($command) = $MYTH_PATH .
|
my($command) = $MYTH_PATH .
|
||||||
"/mythplugins/mythweather/mythweather/scripts/us_nws/nws-alert.pl";
|
"/mythplugins/mythweather/mythweather/scripts/us_nws/nws-alert.pl";
|
||||||
my %data;
|
my %data;
|
||||||
|
@ -51,11 +52,19 @@ foreach my $location (keys %data) {
|
||||||
die "Missing $location!" if (not defined $data{$location}{alerts});
|
die "Missing $location!" if (not defined $data{$location}{alerts});
|
||||||
next if $data{$location}{alerts} =~ /no\s*warning/i;
|
next if $data{$location}{alerts} =~ /no\s*warning/i;
|
||||||
print "\${color5}\${font :size=20}WEATHER ALERT:\n";
|
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 $datetime = ParseDate($data{$location}{updatetime});
|
||||||
my $ago = Delta_Format(DateCalc($datetime, $now), 0, "%mt min");
|
my $ago = Delta_Format(DateCalc($datetime, $now), 0, "%mt min");
|
||||||
|
if (defined $ago) {
|
||||||
$ago = Delta_Format(DateCalc($datetime, $now), 0, "%st sec")
|
$ago = Delta_Format(DateCalc($datetime, $now), 0, "%st sec")
|
||||||
if ($ago =~ /0 minutes/);
|
if ($ago =~ /0 minutes/);
|
||||||
print "\${font}As of $ago ago:\n$data{$location}{alerts}\n";
|
} 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";
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
Loading…
Add table
Reference in a new issue