NAME
Geo::WeatherNOAA - Perl extension for interpreting the NOAA weather data
SYNOPSIS
use Geo::WeatherNOAA;
($date,$warnings,$forecast,$coverage) =
process_city_zone('newport','ri','','get');
foreach $key (keys %$forecast) {
print "$key: $forecast->{$key}\n";
}
print process_city_hourly('newport news', 'va', '', 'get');
or
use Geo::WeatherNOAA;
print print_forecast('newport news','va');
DESCRIPTION
This module is intended to interpret the NOAA zone forecasts and current city hourly data files. It should give a programmer an easy time to use the data instead of having to mine it.
Be aware that if the variable $main::opt_v is set to anything (other than zero or '') then Geo::WeatherNOAA will be verbose on what it's doing with messages sent to STDERR. Useful for debugging.
REQUIRES
Tie::IxHash
LWP::Simple
LWP::UserAgent
Text::Wrap
FUNCTIONS
print_forecast(CITY,STATE,FILENAME,FILEOPT,LWP_UserAgent)
Returns text of the forecast
print_current(CITY,STATE,FILENAME,FILEOPT,LWP_UserAgent)
Returns text of current weather
make_noaa_table(CITY,STATE,FILENAME,FILEOPT,LWP_UserAgent, MaxItems)
This call gives the basic html table with current data and forecast for the next four periods ("tonight", "tomorrow","tomorrow night","day after") and warnings in an (I think) attractive, easy to read way.
Max Items is a way to limit the number of items in the table returned... I think it looks best with no more than 4...5 gets crowded looking.
process_city_hourly(CITY,STATE,FILENAME,FILEOPT,LWP_UserAgent)
FILENAME is the file read from with FILEOPT "usefile" and written to if FILEOPT is "save"
FILEOPT can be one of the following
- save will get and save the data to FILENAME - get will retrieve new data (not store it) - usefile will not retrieve data from URL, use FILENAME for data
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/');
NOTE: You may also set the environment variable <CODE>http_proxy</CODE> and the auto-generated LWP::UserAgent will use LWP::UserAgent::env_proxy(). See LWP::UserAgent for more details.
process_city_zone(CITY,STATE,FILENAME,FILEOPT,LWP_UserAgent)
Call CITY, STATE, FILENAME (explained above), FILEOPT(explained above), and UserAgent (Explained above).
The return is a three element list containing a) a string of the date/time of the forecast, b) a reference to the list of warnings (if any), and c) a reference to the hash of forecast. I recommend calling it like this:
($date, $warnings, $forecast, $coverage) = process_city_zone('newport news','va', '/tmp/va_zone.html', 'save');
Explanation of this call, it returns:
$date - Scalar of the date of the forecast $warnings - Reference to the warnings list - EXAMPLE: foreach (@$warnings) { print; } $forecast - Reference to the forecast KEY, VALUE pairs - EXAMPLE: foreach $key (keys %$forecast) { print "$key: $forecast->{$key}\n"; } $coverage - Scalar of the coverage area of the forecast
get_city_zone(CITY,STATE,FILENAME,FILEOPT,LWP_UserAgent)
This sub is to get the block of data from the data source, which is chosen with the FILEOPTswitch.
get_city_hourly(CITY,STATE,FILENAME,FILEOPT,LWP_UserAgent)
This function gets the current weather from the data source, which is decided from FILEOPT(explained above). Input is CITY, STATE, FILENAME (filename to read/write from if FILEOPTis "get" or "usefile"), and UserAgent.
This function returns a reference to a hash containing the data. It
Same FILEOPTand LWP_UserAgent from above, and process the current weather data into an english sentence.
AUTHOR
Mark Solomon
msolomon@seva.net
http://www.seva.net/~msolomon/
SEE ALSO
perl(1), Tie::IxHash(3), LWP::Simple(3), LWP::UserAgent(3).