< Day Day Up > |
Hack 65. Google by Instant MessengerAccessing Google with AOL Instant Messenger. If we're going to step out beyond the Google interface, why even bother to use the Web at all? The Google API makes it possible to access Google's information in many different ways. Googlematic makes it possible to query Google from the comfort of AOL Instant Messenger. Here's how it works: send a message (a Google query) to the instant messenger buddy googlematic. Googlematic will message you back with the top result for your query. Reply with More and you'll get more results formatted as a numbered list, as shown in Figure 5-24. Figure 5-24. Query to googlematic through AOL Instant MessengerMessage with the number associated with a particular result for further details, as shown in Figure 5-25. Figure 5-25. Requesting further detail for a googlematic resultYou can find the Googlematic script, further instructions, and links to required modules at http://interconnected.org/googlematic. 5.8.1. The CodeHere's all there is to the code: #!/usr/bin/perl -w # googlematic.pl # Provides an AIM interface to Google, using the Google SOAP API # and POE to manage all the activity. # # Usage # ./googlematic.pl & # # Requirements # - Googlematic::IM, Googlematic::Responder, Googlematic::Search, # which are all distributed with this script # - CGI # - HTML::Entities # - Net::AOLIM # - POE # - SOAP::Lite # - XML::Parser # # Essential configuration (below) # - AIM username and password (used in Googlematic::IM) # - Google API Developer Key (used in Googlematic::Search) # # Optional configuration (below) # - Search request throttling (used in Googlematic::Search) # - Limit of number of user sessions open (used in Googlematic::IM) # - Time limit on a user session (used in Googlematic::Responder) # # (c) 2002 Matt Webb <matt@interconnected.org> All rights reserved use strict; use POE; $| = 1; use Googlematic::IM; use Googlematic::Search; # Configuration variables $Googlematic::CONFIG = { aim_username => "xxxxxxx", aim_password => "xxxxxxx", google_key => "your key goes here", searches_per_hour => "35", # the Google limit is 1000/day max_user_sessions => "5", user_session_timeout => "120" # in seconds }; # There are two POE sessions: # 1 - Googlematic::IM, known as 'im', takes care of the Instant Messager # connection and looks after user sessions (which are created as new # POE sessions, and known as Responders). POE::Session->create( package_states => [ Googlematic::IM => [ '_start', 'login_aim', 'loop', 'spawner', 'handler_aim', 'send', '_child', '_stop', 'proxy' ] ] ); # 2 - Googlematic::Search, known as 'google', takes care the SOAP::Lite # object making the searches on Google. Requests to it are sent from the # individual Responders. POE::Session->create( package_states => [ Googlematic::Search => [ '_start', 'loop', 'search', 'reset' ] ] ); # Run the POE machine. $poe_kernel->run( ); exit; |
< Day Day Up > |