AccuWeather script & templates

Templates, scripts for templates, scripts and requests for templates.

Moderators: Moderators, Developers

Author
Message
Alives
Cacti User
Posts: 103
Joined: Mon Jul 11, 2005 11:39 am

AccuWeather script & templates

#1 Post by Alives » Tue Aug 09, 2005 1:46 am

This script monitors 22 different weather variables off the accuweather site. It is a standard perl html scraper script.

enjoy!

P.S. The results, as you can see, arent that accurate. I have another post with WeatherBug scrapes here: http://forums.cacti.net/viewtopic.php?p=38926 but its only 6 variables.

You need the LWP::Simple perl module installed
Attachments
accu.png
accu.png (31.42 KiB) Viewed 45891 times
cacti_host_template_accuweather.xml
(59.46 KiB) Downloaded 3505 times
AccuWeather.pl.txt
(1.68 KiB) Downloaded 3169 times
Last edited by Alives on Tue Aug 09, 2005 2:02 pm, edited 2 times in total.

_JPL_
Cacti User
Posts: 67
Joined: Mon Nov 29, 2004 11:34 am

#2 Post by _JPL_ » Tue Aug 09, 2005 12:34 pm

When I run the script from the command line as the cactiuser I get what looks like the proper output, howver when the poller runs it, it fails.

Command Line Output:
sh-3.00$ scripts/AccuWeather.pl b3l1s3
Dewpoint:25 Humidity:99 WindChill:27 Departure:22 LowPast6hrs:17 ApparentTemp:25 MaxTemp:22 CloudCover:100 MinTemp:25 HighPast6hrs:25


Poller Ouput:
08/09/2005 02:18:45 PM - CMDPHP: Poller[0] Host[115] DS[1404] WARNING: Result from CMD not valid. Partial Result:
08/09/2005 02:18:45 PM - CMDPHP: Poller[0] Host[115] DS[1404] CMD: perl /var/www/html/cacti/scripts/AccuWeather.pl b3l1s3, output: U

Note, that I had to change the URL in the script to make it work for Canada and to show metric.

Alives
Cacti User
Posts: 103
Joined: Mon Jul 11, 2005 11:39 am

#3 Post by Alives » Tue Aug 09, 2005 1:14 pm

yeah... try putting that in quotes or just hardcoding it to the script... your input uses the pipe, |, which i think your shell is trying to interpret. easiest thing to do is to just hard code your script since you probably dont need the flexibility too much...

jaybob
Posts: 12
Joined: Mon Aug 08, 2005 5:14 am
Location: france - toulouse
Contact:

#4 Post by jaybob » Wed Aug 10, 2005 2:41 am

Hi,
when I import the accuweather_template, Cacti says : Error: XML: Hash version does not exist. :x
My Cacti version is 0.8.6c
I don't find where is the bug ??

_JPL_
Cacti User
Posts: 67
Joined: Mon Nov 29, 2004 11:34 am

#5 Post by _JPL_ » Wed Aug 10, 2005 7:39 am

I couldn't import the file but I could copy/paste the contents of the file into the import area.

Alives
Cacti User
Posts: 103
Joined: Mon Jul 11, 2005 11:39 am

#6 Post by Alives » Wed Aug 10, 2005 8:20 am

this was made using cacti 0.8.6f

spoonman
Cacti User
Posts: 299
Joined: Tue May 03, 2005 8:54 am
Location: GA

Hash Error

#7 Post by spoonman » Fri Aug 12, 2005 8:26 am

I found a Hash error while importing into my cacti version f/// its on like line 112 , a variable RealFeel had the trademark symbol right after the work RealFeel, cacti or xml didnlt like that for me, i just removed it and saved the xml template and re-imported it// worked perfectly/

spoonman
Cacti User
Posts: 299
Joined: Tue May 03, 2005 8:54 am
Location: GA

#8 Post by spoonman » Wed Aug 24, 2005 9:16 am

Anyone using this accuweather script??

Does anyone notice that the Humidity is always 50% /// I ran this script agains like 5 zipcodes, always 50 %. Has anyone noitced this, corrected it?? How??

THanks

Alives
Cacti User
Posts: 103
Joined: Mon Jul 11, 2005 11:39 am

#9 Post by Alives » Wed Aug 24, 2005 9:56 am

accuweather isnt all that accurate...thats why i did the weatherbug script... its VERY accurate with live updating.

spoonman
Cacti User
Posts: 299
Joined: Tue May 03, 2005 8:54 am
Location: GA

#10 Post by spoonman » Thu Aug 25, 2005 8:43 am

I understand that but i dont think its accuweathers' site, I ran the script against 5 or so ziips. All said 50 % , even the pics in this thread say 50% for Humidity.....i think its the script?? I just dont see anything wrong right off, and i'm not the best with scripts or code?? Just was wondering if anyone had fixed that variable that pulls Humidity??

Thanks

Alives
Cacti User
Posts: 103
Joined: Mon Jul 11, 2005 11:39 am

#11 Post by Alives » Thu Aug 25, 2005 9:59 am

it is the script... i would be honored if you would fix it as i am only working on the weatherbug one at this point. its just a simple regex, and, as many people will reply, you arent supposed to grab html pages with regex's... but whatever... it was quick adn easy

spoonman
Cacti User
Posts: 299
Joined: Tue May 03, 2005 8:54 am
Location: GA

#12 Post by spoonman » Fri Aug 26, 2005 10:13 am

Calling all Perl Gurus' >> It seems to me the Accuweather scripts has a few flaws in it

if ($content =~ /(\d+)%/g) { $data{Humidity} = $1; }
if ($content =~ /(\d+)%/g) { $data{CloudCover} = $1; }

Those 2 are what I see wrong anyhow, no matter what zip you run the script against it pulls back 50% for Humidity and 99% for cloudcover. All the time!!! I think the search string above is messed up or something or its just finding the wrong data in the source of that web page. Its almost like its pulling back cell width % or something!!! Anyone feel like looking at it more to see if you see what's wrong??

Thanks all.

zoltar
Posts: 4
Joined: Tue Aug 30, 2005 5:17 am

#13 Post by zoltar » Tue Aug 30, 2005 6:53 am

Change lines to these:
if ($content =~ /(\d+)%</g) { $data{Humidity} = $1; }
if ($content =~ /(\d+)%</g) { $data{CloudCover} = $1; }

spoonman
Cacti User
Posts: 299
Joined: Tue May 03, 2005 8:54 am
Location: GA

#14 Post by spoonman » Tue Aug 30, 2005 8:07 am

That did it, all variables now report the correct #'s !!! Thanks for that, I searched all kinds of regex characters and didnt' see that one, yet again i'm not a perl guy!! Thanks again!!!!

spoonman
Cacti User
Posts: 299
Joined: Tue May 03, 2005 8:54 am
Location: GA

#15 Post by spoonman » Tue Aug 30, 2005 8:10 am

Updated Accuweather perl script with corrected variables ( Humidity and CloudCover both reporting 50% for no matter what zip you add ) !! Thanks for the help zoltar!!!
Attachments
accuweather.pl.txt
(1.7 KiB) Downloaded 2381 times

Post Reply