[SimBot-commits] CVS: simbot/plugins weather.pl,1.57,1.58
Status: Abandoned
Brought to you by:
kstange
|
From: Pete P. <fou...@us...> - 2005-05-06 00:01:47
|
Update of /cvsroot/simbot/simbot/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25727/plugins Modified Files: weather.pl Log Message: Added %weather forecast <zip> to get the forecast for that zip. Index: weather.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/weather.pl,v retrieving revision 1.57 retrieving revision 1.58 diff -u -d -p -r1.57 -r1.58 --- weather.pl 5 May 2005 03:48:32 -0000 1.57 +++ weather.pl 6 May 2005 00:01:35 -0000 1.58 @@ -65,7 +65,7 @@ use HTTP::Status; use DBI; # for sqlite database # declare globals -use vars qw( $session $dbh ); +use vars qw( $session $dbh $zip_dbh ); # These constants define the phrases simbot will use when responding # to weather requests. @@ -105,6 +105,9 @@ sub messup_wx { # let's create our database $dbh = DBI->connect('dbi:SQLite:dbname=caches/weather','','', { RaiseError => 1, AutoCommit => 0 }) or die; + + $zip_dbh = DBI->connect('dbi:SQLite:dbname=USzip','','', + { RaiseError => 1, AutoCommit => 0 }) or die; # let's create the table. If this fails, we don't care, as it # probably already exists @@ -764,7 +767,8 @@ sub do_forecast { # for much of this script my ($nick, $channel, $lat, $long) = @_; - + &SimBot::debug(3, 'weather: Received forecast request from ' . $nick + . " for $lat $long\n"); my $serviceURI = 'http://weather.gov/forecasts/xml'; my $method = 'NDFDgenByDay'; my $endpoint = "$serviceURI/SOAP_server/ndfdXMLserver.php"; @@ -886,6 +890,22 @@ sub new_get_wx { my $flags = 0; my ($lat, $long); + if($station =~ /f(ore)?cast/) { + if(defined $args[0] && $args[0] =~ /^\d{5}$/) { # zip code + my $get_lat_long_query = $zip_dbh->prepare_cached( + 'SELECT latitude, longitude FROM uszips' + . ' WHERE zip = ? LIMIT 1'); + $get_lat_long_query->execute($args[0]); + if(($lat, $long) = $get_lat_long_query->fetchrow_array) { + &do_forecast($nick, $channel, $lat, $long); + } else { + &SimBot::send_message($channel, "$nick: I do not know where that zip code is."); + } + } else { + &SimBot::send_message($channel, "$nick: For what US Zip code do you want a forecast?"); + } + return; + } if(($lat) = $station =~ /(-?[\d\.]+)/) { my $long = $args[0]; |