#!/usr/bin/perl # conky-mythtv-weather-build.plx # # Copyright (C) 2013, Bradley M. Kuhn # # This program gives you software freedom; you can copy, modify, convey, # and/or redistribute it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program in a file called 'GPLv3'. If not, write to the: # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor # Boston, MA 02110-1301, USA. # # Quick hack to use mythtv scripts. use strict; use warnings; 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 @ARGV; my($command) = $MYTH_PATH . "/mythplugins/mythweather/mythweather/scripts/us_nws/nws-alert.pl"; my %data; foreach my $location (@ARGV) { open(DATA, "-|", $command, $location) or die "unable to run: $command $location: $!"; while (my $line = ) { die "bad line output in data: $line" unless $line =~ /^\s*(\S+)\s*:\s*:\s*(.+)$/; $data{$location}{$1} = $2; } close DATA; die "error($?) running: $command $location: $!" unless $? == 0; } my $warned = 0; 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"); 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"; } ############################################################################### # # Local variables: # compile-command: "perl -c conky-mythtv-weather-alert.plx" # End: