Capturing a Moment in Time
Build a Google box for a particular moment in time.
Google boxes are a nice addition to your web pages, whether you run a weblog or a news site. But for many Google box searches, the search results won’t change that often, especially for more common search words. The Timely Google box—built upon the ordinary Google box [Hack #67] hack—captures a snapshot of newly indexed or reindexed material at a particular point in time.
Making the Google Box Timely
As you might remember, Google has a
daterange:
search syntax available. This version
of Google box takes advantage of the daterange:[Hack #11] syntax, allowing you to specifying how many
days back you want your query to run. If you don’t
provide a number, the default is 1, and there’s no
maximum. I wouldn’t go back much further than a
month or so. The fewer days back you go the more often the results in
the Google box will change.
Tip
You’ll need the Julian::Day module to get this hack rolling (http://search.cpan.org/search?query=time%3A%3Ajulianday).
The Code
#!/usr/local/bin/perl # timebox.pl # A time-specific Google box # Usage: perl timebox.pl <query> <# results> <# days back> # Your Google API developer's key my $google_key='insert key here'; # Location of the GoogleSearch WSDL file my $google_wdsl = "./GoogleSearch.wsdl"; use strict; use SOAP::Lite; use Time::JulianDay; # Bring in those command-line arguments @ARGV == 3 or die "Usage: perl timebox.pl <query> <# results> <# days back>\n"; my($query, $maxResults, ...
Get Google Hacks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.