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  

Build a Custom Date Range Search Form
Search only Google pages indexed today, yesterday, the last 7 days, or last 30 days
The Code
[Discuss (0) | Link to this hack]

The Code

Note that this script just does a couple of date translations in Perl and redirects the browser to Google, altered query in tow. It's just a regular query as far as Google is concerned, so it doesn't require a developer's API key.


This hack requires an additional module, Time::JulianDay, and won't run without it (http://search.cpan.org/search?query=Time%3A%3AJulianDay).

# goofresh.cgi
# Searches for recently indexed files on Google.
# Usage: goofresh.cgi is called as a CGI with form input,
# redirecting the browser to Google, altered query in tow.
use CGI qw/:standard/;
use Time::JulianDay;
# Build a URL-escaped query.
(my $query = param('query')) =~ s#(\W)#sprintf("%%%02x", ord($1))#ge;
# How many days back?
my $days_back = int param('days_back') || 0;
# What's the current Julian date?
my $julian_date = int local_julian_day(time);
# Redirect the browser to Google with query in tow.
print redirect(
    'http://www.google.com/search?num=100' .
    "&q=$query" .
    "+daterange%3A" . ($julian_date - $days_back) . "-$julian_date"

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.