]> git.donarmstrong.com Git - infobot.git/commitdiff
* Use the google API and other fixes to W3Search [dpkg specific]
authordondelelcaro <dondelelcaro@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 3 Jun 2006 01:14:17 +0000 (01:14 +0000)
committerdondelelcaro <dondelelcaro@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 3 Jun 2006 01:14:17 +0000 (01:14 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/branches/don/dpkg@1280 c11ca15a-4712-0410-83d8-924469b57eb5

src/Modules/W3Search.pl

index 4ce84743c7c3e335e2c5f50e143b84f98f717397..eee5ff0f343855ef3db469c2b96c8b86f71bdde0 100644 (file)
@@ -7,7 +7,7 @@ package W3Search;
 use strict;
 use vars qw(@W3Search_engines $W3Search_regex);
 @W3Search_engines = qw(AltaVista Dejanews Excite Gopher HotBot Infoseek
-               Lycos Magellan PLweb SFgate Simple Verity Google z);
+               Lycos Magellan PLweb SFgate Simple Verity Google);
 $W3Search_regex = join '|', @W3Search_engines;
 
 my $maxshow    = 5;
@@ -28,35 +28,42 @@ sub W3Search {
     return unless &::loadPerlModule("WWW::Search");
 
     eval {
-       $Search = new WWW::Search($where, agent_name => 'Mozilla/4.5');
-    };
-
-    if (!defined $Search) {
-       &::msg($::who, "$where is invalid search.");
-       return;
-    }
-
-    my $Query  = WWW::Search::escape_query($what);
-    $Search->native_query($Query,
-       {
-               num => 10,
-#              search_debug => 2,
-#              search_parse_debug => 2,
+       if ($where eq 'Google') {
+           # key is your Google API key.
+           # Get it from http://api.google.com/createkey
+           $Search = new WWW::Search('Google',key => '')
+       }
+       else {
+           $Search     = new WWW::Search($where);
        }
-    );
-    $Search->http_proxy($::param{'httpProxy'}) if (&::IsParam("httpProxy"));
-    #my $max = $Search->maximum_to_retrieve(10);       # DOES NOT WORK.
+       if (!defined $Search) {
+           &::msg($::who, "$where is invalid search.");
+           return;
+       }
+       
+       my $Query       = WWW::Search::escape_query($what);
+       $Search->native_query($Query,{   num => 10,
+                                        search_debug => 2,
+                                        search_parse_debug => 2,
+                                    }
+       );
+       $Search->http_proxy($::param{'httpProxy'}) if (&::IsParam("httpProxy"));
+       #my $max = $Search->maximum_to_retrieve(10);    # DOES NOT WORK.
 
-    my (@results, $count, $r);
+       my (@results, $count, $r);
+       $count=0;
        $retval = "$where says \002$what\002 is at ";
-    while ($r = $Search->next_result()) {
-       my $url = $r->url();
-       $retval .= ' or ' if ($count > 0);
-       $retval .= $url;
-       last if ++$count >= $maxshow;
+       while ($r = $Search->next_result()) {
+           my $url = $r->url();
+           $retval .= ' or ' if ($count > 0);
+           $retval .= $url;
+           last if ++$count >= $maxshow;
+       }
+       
+       $retval = "$where was unable to find any results for \002$what\002" unless $count > 0;
+       
+       &::performStrictReply($retval);
     }
-
-    &::performStrictReply($retval);
-}
-
+}    
 1;
+