NAME
Geo::WeatherNOAA - Perl extension for getting NOAA Weather(Wx) Data
SYNOPSIS
use Geo::WeatherNOAA;
print get_currentWX_html('NEW YORK','NY');
print_forecast('NEW YORK','NY');
%wx = get_forecast('BOSTON','MA');
print "The forecast is $wx{NEAR}\n";
print "The extended forecast is $wx{EXTENDED}\n";
print "This information was updated $wx{Date}\n";
print "The affected areas are $wx{Coverage}\n";
DESCRIPTION
I needed a way to get NOAA weather data for both web pages and perl scripts for web pages etc. This module gets information from the NOAA web site and "decodes" it into usable format: hashes, lists, english, etc.
FUNCTIONS
The idea behind these function calls is simplicity. Each function needs at least the city and state. If you want to use the neato cacheing function, give the minutes to cache and, optionally, the directory to use to hold the weather data cache.
get_forecast(CITY,STATE,CACHE,CACHEDIR,LWP_UserAgent)
Call with at least to tokens: City and State (Two letter abbr)
The third token, if used will tell the module to use the caching function so that the data will only be retrieved from NOAA when the cached data is this many minutes old. I figured this would be usefull to a web server where only the first 'hit' would have to wait for the remote data.
The fourth argument is the directory in which to cache the data. If omitted, the module will use
/tmp/wxdata
The fifth argument is for a user created LWP::UserAgent(3) which can be configured to work with firewalls. See the LWP::UserAgent(3) manpage for specific instructions. A basic example is like this:
my $ua = new LWP::UserAgent; $ua->proxy(['http', 'ftp'], 'http://proxy.my.net:8080/');
If you merely wish to set your proxy data from environment variables (as in
$ua-
env_proxy>), simply set$Geo::WeatherNOAA::proxy_from_env = 1;
This function returns a hash with the following keys:
Coverage => A list of the affected areas for the forecast Date => Date/time when the data was reported to NOAA NEAR => Newline delineated list, each line contains a colon (:) delin list of day and data. NOTE: If there's no data, the "key" is a weather warning EXTENDED => Same as NEAR but without weather warnings URL => URL where the data originated
It can be used like this:
use Geo::WeatherNOAA; %wx = get_forecast('BOSTON','MA'); print "The forecast is $wx{NEAR}\n"; print "The extended forecast is $wx{EXTENDED}\n"; print "This information was updated $wx{Date}\n"; print "and covers $wx{Coverage}\n";
In examples/wx.cgi, I split the NEAR and EXTENDED fields to make nicer output:
use Geo::WeatherNOAA; %wx = get_forecast('BOSTON','MA'); print "<TABLE>\n"; foreach $line (split "\n", $wx{NEAR}) { my ($day,$data) = split /:/, $line; if ($data) { # Normal line if there are both keys print "<TR><TD>$day</TD><TD>$data</TD></TR>\n"; } else { # Warning line if there's only the $day value print "<TR><TD COLSPAN=2>$day</TD></TR>\n"; } } print "</TABLE>\n";
print_forecast(CITY,STATE)
Prints an english (text) description of the forecast
Its output looks like this:
Forecast for BLACKSBURG, VA for March 6, 1998 WARNING: The national weather service has issued a flood watch for late tonight through monday WARNING: A wind advisory has also been posted for very late tonight through monday... Tonight: Showers...With a chance of thunderstorms. Lows in the upper 40s. South wind around 15 mph. Chance of rain near 100 percent. Monday: Showers with a chance of thunderstorms...Mainly in the morning. Turning cooler. Temperatures falling into the lower 40s. West wind around 15 mph. Chance of rain 90 percent. Monday night: Mostly cloudy with a chance of rain or snow. Breezy. Lows mostly in the 20s. Chance of precipitation 40 percent. Tuesday: Partly cloudy with a chance of snow flurries. Colder and breezy. Highs from the upper 20s to near 40.
get_currentWX(CITY,STATE,CACHE,CACHEDIR,LWP_UserAgent)
Call with at least to tokens: City and State (Two letter abbr)
The third token, if used will tell the module to use the caching function so that the data will only be retrieved from NOAA when the cached data is this many minutes old. I figured this would be usefull to a web server where only the first 'hit' would have to wait for the remote data.
The fourth argument is the directory in which to cache the data. If omitted, the module will use
/tmp/wxdata
The fifth argument is for a user created LWP::UserAgent(3) which can be configured to work with firewalls. See the LWP::UserAgent(3) manpage for specific instructions. A basic example is like this:
my $ua = new LWP::UserAgent; $ua->proxy(['http', 'ftp'], 'http://proxy.my.net:8080/');
If you merely wish to set your proxy data from environment variables (as in
$ua-
env_proxy>), simply set$Geo::WeatherNOAA::proxy_from_env = 1;
This function returns a hash with the following keys:
CITY => Name of reported city SKY/WX => Sky conditions TEMP => Current temp DEWPT => Dewpoint RH => Relative Humidity WIND => Wind direction and speed PRES => Pressure REMARKS => Remarks
get_current_html(CITY,STATE,CACHE)
Call with at least to tokens: City and State (Two letter abbr)
The third token, if used will tell the module to use the caching function so that the data will only be retrieved from NOAA when the cached data is this many minutes old. I figured this would be usefull to a web server where only the first 'hit' would have to wait for the remote data.
This call returns a scalar containing a (sort-of) htmlized english sentence describing the weather in the requested city.
use Geo::WeatherNOAA; $weather = get_currentWX_html('RICHMOND','VA'); print "$weather\n";
The output looks like this:
At 8:00pm EST, Richmond, VA was experiencing cloudy skies at 66°F, wind is south at 15mph.
AUTHOR
Mark Solomon
msolomon@seva.net
http://www.seva.net/~msolomon/wx/
SEE ALSO
perl(1), LWP(3), LWP::UserAgent(3).
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 603:
Non-ASCII character seen before =encoding in '66°F,'. Assuming CP1252