O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  



HACK
#65
Google by Instant Messenger
Accessing Google with AOL Instant Messenger
The Code
[Discuss (0) | Link to this hack]

The Code

Here'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;

Tara Calishain and Matt Webb


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.