]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Weather.pl
comments
[infobot.git] / src / Modules / Weather.pl
index d2a957769c6442aee55afc312061ff6e3cb20665..9fef90e73071b46b9535063ef7dd201428d02537 100644 (file)
@@ -21,15 +21,24 @@ BEGIN {
 
 sub Weather {
        my ($args) = @_;
-       &::performStrictReply(&queryText($args));
+       &::performStrictReply(&queryText($args, 'weather'));
+       return;
+}
+
+sub Metar {
+       my ($args) = @_;
+       &::performStrictReply(&queryText($args, 'metar'));
        return;
 }
 
 sub queryText {
     my ($station) = shift;
-    $station = uc($station);
+    my ($wxmode) = shift;
     my $result;
 
+    $station = uc($station);
+    $station =~ s/for //i;
+
     if ($no_weather) {
        return 0;
     } else {
@@ -46,7 +55,7 @@ sub queryText {
 
        $ua->timeout(10);
        my $request = new HTTP::Request('GET', "http://weather.noaa.gov/weather/current/$station.html");
-       my $response = $ua->request($request); 
+       my $response = $ua->request($request);
 
        if (!$response->is_success) {
            if ($response->code == 404) {
@@ -60,7 +69,10 @@ sub queryText {
        }
 
        $content = $response->content;
-       $content =~ s|.*?current weather conditions.*?<BR>([^<]*?)\s*<.*?</TR>||is;
+       $content =~ s|.*?<BODY[^>]*>||is;
+       #$content =~ s|.*?current weather conditions.*?<BR>([^<]*?)\s*<.*?</TR>||is;
+       $content =~ s|.*?current weather conditions[^<]*(<[^>]+>\s*)+||is;
+       $content =~ s|([^<]*?)\s*<.*?</TR>||is;
        my $place = $1;
        chomp $place;
 
@@ -91,6 +103,10 @@ sub queryText {
        $min_temp = $1;
 
        if ($time) {
+           if ($wxmode eq 'metar' && defined($feat{'ob'})) {
+               return ("METAR " . $place . ": " . $feat{'ob'});
+           }
+
            $result = "$place; $id; last updated: $time";
            foreach (sort keys %feat) {
                next if $_ eq 'ob';