#!/usr/local/bin/perl
# gawsh.cgi
# GAWSH: Google API Web Search by Host
# Searches Google for a query string, and displays a list of
# hosts on which search results were found; user can then
# expand each host to see results restricted to that host.
# See http://www.staggernation.com/gawsh/readme.html for info.
# By Kevin Shay, kevin [AT] staggernation [DOT] com
# Version 1.0, 4/24/02
# tell perl where to find SOAP::Lite
use lib qw( /home/staggernation/lib/5.6.0/
/home/staggernation/lib/site_perl/5.6.0);
use SOAP::Lite;
use CGI;
use URI::Escape;
# this library contains generic code for all the Google API scripts
require('ga_lib.pl');
# this library contains code for the DHTML outlining
require('ga_outlinelib.pl');
my ($cgi, $docs_path, $filter, $google_key, $html_output, $level, $params,
$query, $response, $service, $this_script, $top);
# constants
$this_script = $ENV{'SERVER_URL'} . $ENV{'SCRIPT_NAME'};
$docs_path = 'http://www.staggernation.com/gawsh';
#$google_key = 'YOUR_KEY_HERE';
$google_key = require('key.pl');
$cgi = new CGI;
# put CGI params into hash
$params = cgi_params($cgi);
print "Content-type: text/html\n\n";
# user can enter their own key
$google_key = ($params->{'key'} || $google_key);
$top = $params->{'host'} ? 0 : 1; # are we at the top level?
# parameter validation and defaults
$params->{'start'} ||= 0;
# do we have a query?
if ($params->{'q'}) {
# load the Google service definition
$service = SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl");
$query = $params->{'q'};
# if we're expanding a host, this will be passed;
# restrict search by host
if ($params->{'host'}) {
$query .= " site:$params->{'host'}";
$filter = 0;
} else {
$filter = 1;
}
$response = google_search($service, $google_key, $query, $params->{'start'}, 10, $filter);
$i = 0;
if ($top) {
$html_output .= <<"EOH";
Click on a triangle to expand or collapse a host.
Hosts with results for $params->{'q'}:
![]()
EOH
# text to be prepended to navigation for this level
$params->{'count_text'} = 'From pages ';
} else {
# contents of this div will be grabbed from the hidden frame by the main frame
$html_output .= qq{
|
$result->{'title'}
$result->{'snippet'} $result->{'URL'} - $result->{'cachedSize'} - Cached |
|
|
$host |