Permalink
Browse files

- Google weather

- Google weather forecast
  • Loading branch information...
1 parent d7c10af commit 067d47e5d538aaab51284214902d7a7c426a3aad @relrod committed Aug 14, 2011
Showing with 28 additions and 0 deletions.
  1. +1 −0 Makefile.PL
  2. +27 −0 b4bot.pl
View
@@ -13,6 +13,7 @@ requires(
'YAML',
'Proc::Daemon',
'Net::IP',
+ 'Weather::Google',
);
auto_install;
View
@@ -17,6 +17,7 @@ package MyBot;
use YAML;
use Net::IP;
use Socket;
+use Weather::Google;
# TODO: Better handling if both of these fail.
my $config = YAML::LoadFile('config.yaml');
@@ -214,6 +215,32 @@ sub said {
}
}
+ when (/${comchar}gweather (.+)/) {
+ my $wx_query = $1;
+ my $weather = new Weather::Google($wx_query)->current();
+ if (!$weather) {
+ return 'FFFFFUUUUUUUUUUUUUUUUUU! Sorry, something went wrong.';
+ } else {
+ return 'Weather for `'.$1.'`: Current conditions: '.
+ $weather->{'condition'}.'. Temperature: '.$weather->{'temp_f'}.
+ 'F or '.$weather->{'temp_c'}.'C. '.$weather->{'wind_condition'}.
+ '. '.$weather->{'humidity'}.'.';
+ }
+ }
+
+ when (/${comchar}forecast (.+)/) {
+ my $wx_query = $1;
+ my $weather = new Weather::Google($wx_query);
+ my $forecast = 'Forecast for `'.$wx_query.'`: ';
+ for my $day (0..3) {
+ my $g_forecast = $weather->forecast($day);
+ $forecast .= $g_forecast->{'day_of_week'}.': '.
+ $g_forecast->{'condition'}.'; High/Low: '.
+ $g_forecast->{'high'}.'F/'.$g_forecast->{'low'}.'F. ';
+ }
+ return $forecast;
+ }
+
# These are administrative commands. Eventually is_admin will check against the db.
when (/${comchar}join (.+)/) {
if (is_admin($message->{'raw_nick'})) {

0 comments on commit 067d47e

Please sign in to comment.