Google Hacks 2Nd Edition [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Google Hacks 2Nd Edition [Electronic resources] - نسخه متنی

Tara Calishain

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







Hack 65. Google by Instant Messenger

Accessing 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 Messenger


Message 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 result


You can find the Googlematic
script, further instructions, and links to required modules at
http://interconnected.org/googlematic.


5.8.1. 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

/ 209