AccuWeather.pl Cacti Fix

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"

 

 

 

2 thoughts on “AccuWeather.pl Cacti Fix”

  1. Shelby —

    Some people don’t realize that RealFeel Temp is actually a patented algorithm created by AccuWeather.com meteorologists. I think “Real Feel” like “Kleenex” or “Lego” has kind of moved into the vernacular. So, the formula isn’t really a secret but it is AccuWeather’s property.

    However, we like working with developers and if you’re interested in working with our code we’re ready to make it easy for you. Here is the email of our dev partnership guy [email protected]. if you’ve got an idea for a killer widget, toolbar, or something too revolutionary to describe, etc. please reach out to us. We’ll get you whatever weather data you need. We’re releasing new apps all the time to try and meet the needs of every user — mac and pc, opera and firefox, vista and iphone, spanish and english, and so forth.

    Cheers,

    Justin Roberti
    AccuWeather, Inc.

Comments are closed.