( param('query') and param('start') =~ /^(?:$date_regex)?$/and param('end') =~ /^(?:$date_regex)?$/ ) ordie qq{usage: goocount.pl query="{query}" start={date}end={date}\n};# Julian date manipulationmy $query = param('query');my $yesterday_julian = int local_julian_day(time) - 1;my $start_julian = (param('start') =~ /$date_regex/)? julian_day($1,$2,$3) : $yesterday_julian;my $end_julian = (param('end') =~ /$date_regex/)? julian_day($1,$2,$3) : $yesterday_julian;# Create a new Google SOAP requestmy $google_search = SOAP::Lite->service("file:$google_wdsl");print qq{"date","count"\n};# Iterate over each of the Julian dates for your queryforeach my $julian ($start_julian..$end_julian) {$full_query = "$query daterange:$julian-$julian";# Query Googlemy $result = $google_search ->doGoogleSearch($google_key, $full_query, 0, 10, "false", "", "false","", "latin1", "latin1");}# Outputprint'"',sprintf("%04d-%02d-%02d", inverse_julian_day($julian)),qq{","$result->{estimatedTotalResultsCount}"\n};63.2 Running the HackRun the script from the command line, specifying a query, start, and end dates. Perhaps you'd liketo see track mentions of the latest Macintosh operating system (code name "Jaguar") leading up to,on, and after its launch (August 24, 2002). The following invocation sends its results to a commaseparated(CSV) file for easy import into Excel or a database:% perl goocount.pl query="OS X Jaguar" \start=2002-08-20 end=2002-08-28 > count.csvLeaving off the > and CSV filename sends the results to the screen for your perusal:% perl goocount.pl query="OS X Jaguar" \start=2002-08-20 end=2002-08-28If you want to track results over time, you could run the script every day (using cron under Unixor the scheduler under Windows), with no date specified, to get the information for that day's date.
Just use >> filename.csv to append to the filename instead of writing over it. Or youcould get the results emailed to you for your daily reading pleasure.63.3 The ResultsHere's that search for Jaguar, the new Macintosh operating system:% perl goocount.pl query="OS X Jaguar" \start=2002-08-20 end=2002-08-28"date","count""2002-08-20","18""2002-08-21","7""2002-08-22","21""2002-08-23","66""2002-08-24","145""2002-08-25","38""2002-08-26","94""2002-08-27","55""2002-08-28","102"Notice the expected spike in new finds on release day, August 24th.63.4 Working with These ResultsIf you have a fairly short list, it's easy to just look at the results and see if there are any spikes orparticular items of interest about the result counts. But if you have a long list or you want a visualoverview of the results, it's easy to use these numbers to create a graph in Excel or your favoritespreadsheet program.Simply save the results to a file, and then open the file in Excel and use the chart wizard to createa graph. You'll have to do some tweaking but just generating the chart generates an interestingoverview, as shown in Figure 6-3.Figure 6-3. Excel graph tracking mentions of OS X Jaguar63.5 Hacking the Hack