I got bored today and decided that I wanted to monitor weather in different locations with my Cacti setup. I obtained a copy of the AccuWeather perl script and also the XML file for Cacti, loaded it up and what do you know… It wasn’t graphing the Temp or the RealFeel®.

With a little help from my friend Wezzul I was able to get it graphing correctly. I present to you the fixed perl script.

#!/usr/bin/perl
use warnings;
use strict;

use LWP::Simple;

my $httpaddr = "http://wwwa.accuweather.com/forecast-current-conditions.asp?partner=forecastfox&myadc=0&traveler=1&zipcode=" . $ARGV[0] . "&metric=0";

my %data;
my $content = LWP::Simple::get($httpaddr) or die "Couldn't get it!";
$content =~ s/\ |\n//g;

# regex in html source order
if ($content =~ /(-?\d+)°/g) { $data{Temp} = $1; }
if ($content =~ /RealFeel®< \/a>:< \/div>\s+

(-?\d+)°F< \/div>/g) { $data{RealFeel} = $1; }
if ($content =~ /(\d+)%/g) { $data{Humidity} = $1; }
if ($content =~ /(\d+)%/g) { $data{CloudCover} = $1; }
if ($content =~ /(\d+) mi/g) { $data{Visibility} = $1; }
if ($content =~ /(-?\d+)°/g) { $data{MaxTemp} = $1; }
if ($content =~ /(-?\d+)°/g) { $data{Dewpoint} = $1; }
if ($content =~ /(-?\d+)°/g) { $data{MinTemp} = $1; }
if ($content =~ /(\d+) ft/g) { $data{Ceiling} = $1; }
if ($content =~ /(-?\d+)°/g) { $data{Departure} = $1; }
if ($content =~ /(-?\d+)°/g) { $data{ApparentTemp} = $1; }
if ($content =~ /(-?\d+)°/g) { $data{HighPast6hrs} = $1; }
if ($content =~ /(-?\d+)°/g) { $data{WindChill} = $1; }
if ($content =~ /(-?\d+)°/g) { $data{LowPast6hrs} = $1; }
if ($content =~ /(\d+) mph/g) { $data{WindSpeed} = $1; }
if ($content =~ /(\d+) in/g) { $data{PrecipPast3hrs} = $1; }
if ($content =~ /(\d+) in/g) { $data{PrecipPast6hrs} = $1; }
if ($content =~ /(\d+) mph/g) { $data{WindGusts} = $1; }
if ($content =~ /(\d+) in/g) { $data{PrecipPast24hrs} = $1; }
if ($content =~ /(-?\d+\.\d+)"/g) { $data{Pressure} = $1; }
if ($content =~ /(\d+) in/g) { $data{SnowOnGround} = $1; }
for (keys %data) {
printf "%s:%s ", $_, $data{$_};
}
print "\n"