]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/Weather.pl
- added weather from Nathan Moschkin <logeist@guinerd.myip.org>. Thanks!
[infobot.git] / src / Modules / Weather.pl
1 #
2 #  Weather.pl: Frontend to GEO::Weather (weather.com).
3 #      Author: logeist
4 #     Version: v0.1 (20020512).
5 #     Created: 20020512.
6 #
7
8 package Weather;
9
10 use IO::Socket;
11 use strict;
12
13 ###local $SIG{ALRM} = sub { die "alarm\n" };
14
15 sub Weather {
16     my ($query) = @_;
17     my (@weatherloc, $whash); 
18     my $retval;
19
20     return unless &::loadPerlModule("Geo::Weather");
21     my $weather = new Geo::Weather;
22
23     for ($query) {
24         s/^[\s\t]+//;
25         s/[\s\t]+$//;
26         s/[\s\t]+/ /;
27     }
28
29     @weatherloc = split /,\s*/, $query;
30
31     if (@weatherloc == 1) { 
32         $whash = $weather->get_weather ("$weatherloc[0]");
33     } else {
34         $whash = $weather->get_weather ("$weatherloc[0]", "$weatherloc[1]");
35     }
36
37     if (!ref $whash) {
38         $retval = "I'm sorry, not able to return weather conditions for $query";
39         &::performStrictReply($retval);
40         undef $weather;
41         return;
42     }
43
44     $retval = "Current conditions in $whash->{city}, $whash->{state}: $whash->{cond}, $whash->{temp}° F.  Winds $whash->{wind} MPH.  Dewpoint: $whash->{dewp}° F, Relative Humidity: $whash->{humi}%,";
45
46     if ($whash->{visb} eq 'Unlimited') {
47         $retval .= " Visibility: $whash->{visb}, ";
48     } else {
49         $retval .= " Visibility: $whash->{visb} mi., ";
50     }
51
52     $retval .= " Barometric Pressure: $whash->{baro} in.";
53     if($whash->{heat} ne 'N/A') {
54         $retval .= " Heat Index: $whash->{heat}° F.";
55     }
56
57     &::performStrictReply($retval);
58     undef $weather;
59 }
60
61 1;