CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Can you fix this pm :)


New User

Sep 26, 2011, 8:11 PM

Post #1 of 1 (583 views)
Can you fix this pm :) Can't Post


I am using an infobot version for IRC that uses modules - (pm's) on a windows XP box using strawberry perl. Here is the version I am using... . I have it working pretty well except I would like to be able to use the weather pm to access instead of

Back in the early 90's I could setup perl programs on unix servers but I have been out of the loop since Bill Clinton left office. I would greatly appreciate it if someone with a younger mind than I have could help me out getting this pm to work.

Here is a sample of what it does now using NOAA. Sometimes it display's all the info and sometimes it misses a little of the information at the end of the line.

[9:44pm] <Seaboard> weather pbi
[9:44pm] <jutroh> PALM BEACH INTERNATIONAL, FL, United States ; Conditions at; last updated: Conditions at; Dew Point: 73.9 F (23.3 C); Pressure (altimeter): 29.94 in. Hg (1013 hPa); Relative Humidity: 84%; Sky conditions: overcast; Temperature: 79.0 F (26.1 C); Visibility: 10 mile(s); Wind: Calm

NOAA has changed there html pages for u.s. weather, so the weather pm can't read the location in the same way as it does for international weather.

[9:49pm] <Seaboard> weather cybr
[9:49pm] <jutroh> Brandon, Man., Canada ; (CYBR) 49-55N 099-57W 409M; last updated: Sep 26, 2011 09:00 PM EDT; Dew Point: 44 F (7 C); Pressure (altimeter): 29.84 in. Hg (1010 hPa); Relative Humidity: 42%; Sky conditions: mostly cloudy; Temperature: 68 F (20 C); Visibility: 15 mile(s); Wind: from the S (190 degrees) at 16 MPH (14 KT)

If its allot of trouble to get it to work for wunderground... noaa would be fine if one of you can fix it :)

Here is the that I am using:

# NOAA Weather module.
# kevin lenzo (C) 1999 -- get the weather forcast NOAA.
# feel free to use, copy, cut up, and modify, but if
# you do something cool with it, let me know.
# $Id:,v 1.11 2005/01/21 20:58:03 rich_lafferty Exp $

package weather;

my $no_weather;
my $default = 'KAGC';

$no_weather = 0;
eval "use LWP::UserAgent";
$no_weather++ if ($@);

sub get_weather {
my ($station) = shift;
my $result;

# make this work like Aviation
$station = uc($station);

my $station = uc($2);
$station =~ s/[?!]$//;
$station =~ s/\s+$//g;
return "'$station' doesn't look like a valid ICAO airport identifier."
unless $station =~ /^[\w\d]{3,4}$/;
$station = "C" . $station if length($station) == 3 && $station =~ /^Y/;
$station = "K" . $station if length($station) == 3;

if ($no_weather) {
return 0;
} else {

my $ua = new LWP::UserAgent;
if (my $proxy = main::getparam('httpproxy')) { $ua->proxy('http', $proxy) };


my $request = new HTTP::Request('GET', "$station.html");
my $response = $ua->request($request);

if (!$response->is_success) {
return "Something failed in connecting to the NOAA web server. Try again later.";

$content = $response->content;

if ($content =~ /ERROR/i) {
return "I can't find that station code (see for locations codes)";

$content =~ s|.*?current weather conditions:<BR>(.*?)</B>.*?</TR>||is;
my $place = $1;

# $content =~ s|.*?<TR>(?:\s*<[^>]+>)*\s*([^<]+)\s<.*?</TR>||is;
my $place = $1;
chomp $place;

$content =~ s|.*?<TR>(?:\s*<[^>]+>)*\s*([^<]+)\s<.*?</TR>||is;
my $id = $1;
chomp $id;

$content =~ s|.*?conditions at.*?</TD>||is;

$content =~ s|.*?<OPTION SELECTED>\s+([^<]+)\s<OPTION>.*?</TR>||s;
my $time = $1;
$time =~ s/-//g;
$time =~ s/\s+/ /g;

$content =~ s|\s(.*?)<TD COLSPAN=2>||s;
my $features = $1;

my %feat;
while ($features =~ s|.*?<TD ALIGN[^>]*>(?:\s*<[^>]+>)*\s+([^<]+?)\s+<.*?<TD>(?:\s*<[^>]+>)*\s+([^<]+?)\s<.*?/TD>||s) {
my ($f,$v) = ($1, $2);
chomp $f; chomp $v;
$feat{$f} = $v;

$content =~ s|.*?>(\d+\S+\s+\(\S+\)).*?</TD>||s; # max temp;
$max_temp = $1;
$content =~ s|.*?>(\d+\S+\s+\(\S+\)).*?</TD>||s;
$min_temp = $1;

if ($time) {
$result = "$place; $id; last updated: $time";
foreach (sort keys %feat) {
next if $_ eq 'ob';
$result .= "; $_: $feat{$_}";
my $t = time();
} else {
$result = "I can't find that station code (see for locations and codes)";
return $result;

sub scan (&$$) {
my ($callback,$message,$who) = @_;

if (::getparam('weather')
and ($message =~ /^\s*(wx|weather)\s+(?:for\s+)?(.*?)\s*\?*\s*$/)) {
my $code = $2;
return 'NOREPLY';
return undef;



=head1 NAME - Get the weather from a NOAA server






weather [for] <station>


Contacts C<> and gets the weather report for a given

=head1 AUTHORS

Kevin Lenzo


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives