Save the following code as a CGI script ["How to Run
the Hacks" in the Preface] called
google_mindshare.cgi in your web
site's cgi-bin directory.
#!/usr/local/bin/perl
# google_mindshare.cgi
# This implementation by Rael Dornfest,
# http://www.raelity.org/lang/perl/google/googleshare/
# Based on an idea by Steven Johnson,
# http://www.stevenberlinjohnson.com/movabletype/archives/000009.html
# Your Google API developer's key.
my $google_key='insert key here';
# Location of the GoogleSearch WSDL file.
my $google_wdsl = "./GoogleSearch.wsdl";
use SOAP::Lite;
use CGI qw/:standard *table/;
print
header( ),
start_html("Googleshare Calculator"),
h1("Googleshare Calculator"),
start_form(-method=>'GET'),
'Query: ', br( ), textfield(-name=>'query'),
p( ),
'Person: ',br( ), textfield(-name=>'person'),
p( ),
submit(-name=>'submit', -value=>'Calculate'),
end_form( ), p( );
if (param('query') and param('person')) {
my $google_search = SOAP::Lite->service("file:$google_wdsl");
# Query Google for they keyword, keywords, or phrase.
my $results = $google_search ->
doGoogleSearch(
$google_key, '"'.param('query').'"', 0, 1, "false", "", "false",
"", "latin1", "latin1"
);
# Save the results for the Query.
my $query_count = $results->{estimatedTotalResultsCount};
my $results = $google_search ->
doGoogleSearch(
$google_key, '+"'.param('query').'" +"'.param('person').'"', 0, 1,
"false", "", "false", "", "latin1", "latin1"
);
# Save the results for the Query AND Person.
my $query_person_count = $results->{estimatedTotalResultsCount};
print
p(
b(sprintf "%s has a %.2f%% googleshare of %s",
param('person'),
($query_person_count / $query_count * 100),
'"'.param('query').'"'
)
)
}
print end_html( );