small-hacks/conky-mythtv-weather-build.plx

62 lines
2 KiB
Text
Raw Normal View History

2013-08-25 12:48:39 -04:00
#!/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;
2013-08-25 13:13:18 -04:00
use Date::Manip;
2013-08-25 12:48:39 -04:00
2013-08-25 13:13:18 -04:00
if (@ARGV != 3) {
print STDERR "usage: $0 /path/to/mythtv/git/checkout <units> <location>\n";
2013-08-25 12:48:39 -04:00
exit 1;
}
2013-08-25 13:13:18 -04:00
my($MYTH_PATH, $UNITS, $LOCATION) = @ARGV;
2013-08-25 12:48:39 -04:00
2013-08-25 13:13:18 -04:00
my($forecastCmd) = $MYTH_PATH .
"/mythplugins/mythweather/mythweather/scripts/us_nws/ndfd18.pl";
2013-08-25 12:48:39 -04:00
2013-08-25 13:13:18 -04:00
open(FORECAST, "-|", $forecastCmd, '-u', $UNITS, $LOCATION)
or die "unable to run: $forecastCmd -u $UNITS $LOCATION: $!";
my %forecast;
while (my $line = <FORECAST>) {
die "bad line output in forecast: $line"
unless $line =~ /^\s*(\S+)\s*:\s*:\s*(.+)$/;
$forecast{$1} = $2;
}
close FORECAST;
die "error($?) running: $forecastCmd -u $UNITS $LOCATION: $!" unless $? == 0;
$forecast{updatetime} =~ s/\s*Last\s+Updated\s+on\s*//;
my $now = ParseDate("now");
my $x = Delta_Format(DateCalc(ParseDate($forecast{updatetime}), $now), 0,
"%mt minutes ago");
$forecast{updatetime} = $x if defined $x;
$forecast{updatetime} = "as of $forecast{updatetime}";
2013-08-25 12:48:39 -04:00
###############################################################################
#
# Local variables:
# compile-command: "perl -c conky-mythtv-weather-build.plx"
# End: