Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


Weatherbug work with Metric Data

 
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates
Author Message
bodo.bach



Joined: 02 Jul 2008
Posts: 9

PostPosted: Tue Oct 07, 2008 8:55 am    Post subject: Weatherbug work with Metric Data Reply with quote

Hi,

here the weatherbug.pl script changes for working with metric data:
-----------------------------------------

#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;

my $timeout = 8;
my $total_time = 36;
my $httpaddr = "http://www.aws.com/wx.asp?Units=1&id=" . $ARGV[0];
my $content;
my $fail = 0;
my $tries = 0;
my %data;
my %trash;

do{
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $timeout;
$tries++;
$content = LWP::Simple::get($httpaddr);
alarm 0;
};
} while (!$content && $tries <= int($total_time / $timeout));

$data{Tries} = $tries;

if (!$content) {
exit(1);
}

$_ = $content;
s/nbsp;/ /g;
s/<.+?>//g;
s/\s+/ /g;

# regex in html source order
if ($_ =~ /Temperature\(\DC\)\s(-?\d+?\.\d+?)\s/g) { $data{Temp} = $1; }
if ($_ =~ /Humidity\s\(\D\)\s(\d+?\.\d+?)\s/g) { $data{Humidity} = $1; }
if ($_ =~ /Wind\s\(Kph\).+?(\d+?\.\d+?)\s/g) { $data{Wind} = $1; }
if ($_ =~ /Daily\sRain\s\(\cm\)\s(\d+?\.\d+?)\s/g) { $data{Rain} = $1; }
if ($_ =~ /Pressure\(kPa\)\s(\d+?\.\d+?)\s/g) { $data{Pressure} = $1; }
if ($_ =~ /WIND\sCHILL:\s(\d+?\.\d+?)\s/g) { $data{FeelsLike} = $1; }
if ($_ =~ /DEW\sPOINT:\s(\d+?\.\d+?)\s/g) { $data{DewPoint} = $1; }

for (keys %data) {
printf "%s:%s ", $_, $data{$_};
}
print "\n";

-----------------------------------------------------------------

And don't forget to change the graph-template from "F" to "°C" and "in." to "cm" and so on......


Greetings
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group