|
|
| Author |
Message |
Alives Cacti User
Joined: 11 Jul 2005 Posts: 103
|
Posted: Tue Aug 09, 2005 1:46 am Post subject: AccuWeather script & templates |
|
|
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
| Description: |
|
| Filesize: |
31.42 KB |
| Viewed: |
22994 Time(s) |

|
| Description: |
|
 Download |
| Filename: |
AccuWeather.pl.txt |
| Filesize: |
1.68 KB |
| Downloaded: |
1529 Time(s) |
| Description: |
|
 Download |
| Filename: |
cacti_host_template_accuweather.xml |
| Filesize: |
59.46 KB |
| Downloaded: |
1642 Time(s) |
Last edited by Alives on Tue Aug 09, 2005 2:02 pm; edited 2 times in total |
|
| Back to top |
|
 |
_JPL_ Cacti User
Joined: 29 Nov 2004 Posts: 58
|
Posted: Tue Aug 09, 2005 12:34 pm Post subject: |
|
|
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.
|
|
| Back to top |
|
 |
Alives Cacti User
Joined: 11 Jul 2005 Posts: 103
|
Posted: Tue Aug 09, 2005 1:14 pm Post subject: |
|
|
| 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...
|
|
| Back to top |
|
 |
jaybob
Joined: 08 Aug 2005 Posts: 12 Location: france - toulouse
|
Posted: Wed Aug 10, 2005 2:41 am Post subject: |
|
|
Hi,
when I import the accuweather_template, Cacti says : Error: XML: Hash version does not exist.
My Cacti version is 0.8.6c
I don't find where is the bug ??
|
|
| Back to top |
|
 |
_JPL_ Cacti User
Joined: 29 Nov 2004 Posts: 58
|
Posted: Wed Aug 10, 2005 7:39 am Post subject: |
|
|
| I couldn't import the file but I could copy/paste the contents of the file into the import area.
|
|
| Back to top |
|
 |
Alives Cacti User
Joined: 11 Jul 2005 Posts: 103
|
Posted: Wed Aug 10, 2005 8:20 am Post subject: |
|
|
| this was made using cacti 0.8.6f
|
|
| Back to top |
|
 |
spoonman Cacti User
Joined: 03 May 2005 Posts: 244
|
Posted: Fri Aug 12, 2005 8:26 am Post subject: Hash Error |
|
|
| 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/
|
|
| Back to top |
|
 |
spoonman Cacti User
Joined: 03 May 2005 Posts: 244
|
Posted: Wed Aug 24, 2005 9:16 am Post subject: |
|
|
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
|
|
| Back to top |
|
 |
Alives Cacti User
Joined: 11 Jul 2005 Posts: 103
|
Posted: Wed Aug 24, 2005 9:56 am Post subject: |
|
|
| accuweather isnt all that accurate...thats why i did the weatherbug script... its VERY accurate with live updating.
|
|
| Back to top |
|
 |
spoonman Cacti User
Joined: 03 May 2005 Posts: 244
|
Posted: Thu Aug 25, 2005 8:43 am Post subject: |
|
|
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
|
|
| Back to top |
|
 |
Alives Cacti User
Joined: 11 Jul 2005 Posts: 103
|
Posted: Thu Aug 25, 2005 9:59 am Post subject: |
|
|
| 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
|
|
| Back to top |
|
 |
spoonman Cacti User
Joined: 03 May 2005 Posts: 244
|
Posted: Fri Aug 26, 2005 10:13 am Post subject: |
|
|
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.
|
|
| Back to top |
|
 |
zoltar
Joined: 30 Aug 2005 Posts: 4
|
Posted: Tue Aug 30, 2005 6:53 am Post subject: |
|
|
Change lines to these:
if ($content =~ /(\d+)%</g) { $data{Humidity} = $1; }
if ($content =~ /(\d+)%</g) { $data{CloudCover} = $1; }
|
|
| Back to top |
|
 |
spoonman Cacti User
Joined: 03 May 2005 Posts: 244
|
Posted: Tue Aug 30, 2005 8:07 am Post subject: |
|
|
| 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!!!!
|
|
| Back to top |
|
 |
spoonman Cacti User
Joined: 03 May 2005 Posts: 244
|
Posted: Tue Aug 30, 2005 8:10 am Post subject: |
|
|
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!!!
| Description: |
|
 Download |
| Filename: |
accuweather.pl.txt |
| Filesize: |
1.7 KB |
| Downloaded: |
1052 Time(s) |
|
|
| Back to top |
|
 |
|