]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Weather.pl
ws
[infobot.git] / src / Modules / Weather.pl
index 2cdf25b10dc7e1ae2f2c8484365bfd961d6e18e8..bf1c05e017f8a9ddd9868c9c86ee2c6177ac7b66 100644 (file)
@@ -27,9 +27,11 @@ sub Weather {
 
 sub queryText {
     my ($station) = shift;
-    $station = uc($station);
     my $result;
 
+    $station = uc($station);
+    $station =~ s/for //i;
+
     if ($no_weather) {
        return 0;
     } else {
@@ -46,7 +48,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,10 +62,11 @@ sub queryText {
        }
 
        $content = $response->content;
-       $content =~ s|.*?current weather conditions.*?<BR>([^<]*)<.*?</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;
-       $content =~ s|.*?<TR>(?:\s*<[^>]+>)*\s*([^<]+)\s<.*?</TR>||is;
-       $place .= $1;
        chomp $place;
 
        $content =~ s|.*?<TR>(?:\s*<[^>]+>)*\s*([^<]+)\s<.*?</TR>||is;
@@ -72,7 +75,8 @@ sub queryText {
 
        $content =~ s|.*?conditions at.*?</TD>||is;
 
-       $content =~ s|.*?<OPTION SELECTED>\s+([^<]+)\s<OPTION>.*?</TR>||s;
+       #$content =~ s|.*?<OPTION SELECTED>\s+([^<]+)\s<OPTION>.*?</TR>||s; # local time
+       $content =~ s|.*?<BR>\s+([^<]+?)\s*</FORM>.*?</TR>||s; # UTC
        my $time = $1;
        $time =~ s/-//g;
        $time =~ s/\s+/ /g;