]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Weather.pl
* Add vim formatting comments ( # vim:ts=4:sw=4:expandtab:tw=80 )
[infobot.git] / src / Modules / Weather.pl
index 1b3badec58f6963f6eee5794b909fbcdd994d6d2..d6a2f802e4cdd91e5a59429471863cd4936b4b73 100644 (file)
@@ -21,12 +21,19 @@ 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;
+    my ($wxmode) = shift;
     my $result;
 
     $station = uc($station);
@@ -44,19 +51,20 @@ sub queryText {
        }
 
        my $ua = new LWP::UserAgent;
-       $ua->proxy('http', $::param{'httpProxy'}) if (&::IsParam("httpProxy"));
+       $ua->proxy('http', $::param{'httpProxy'}) if (&::IsParam('httpProxy'));
 
        $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) {
                return "I can't find station code \"$station\""
                    . " (see http://www.nws.noaa.gov/oso/site.shtml"
+                   . " or http://www.nws.noaa.gov/tg/siteloc.shtml"
                    . " for ICAO locations codes).";
            } else {
-               return "Something failed in connecting to the NOAA web"
+               return 'Something failed in connecting to the NOAA web'
                    . " server. Try again later.";
            }
        }
@@ -96,6 +104,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';
@@ -120,6 +132,8 @@ if (0) {
 
 1;
 
+# vim:ts=4:sw=4:expandtab:tw=80
+
 __END__
 
 =head1 NAME