Debian Codegraph @

Programs/AutoSearch

raw ◀ ▶
1 Debian patch touch this file
1 #!perl -w
2 #
3 # AutoSearch
4 # Copyright (c) 1996-1997 University of Southern California.
5 # All rights reserved.
6 # $Id: AutoSearch,v 1.2 2010-12-02 23:46:30 Martin Exp $
7 #
8 # Complete copyright notice follows below.
9
10 =head1 NAME
11
12 AutoSearch -- a web-search tracking application
13
14 =head1 SYNOPSIS
15
16 AutoSearch [--stats] [--verbose] -n "Query Name" -s "query string" --engine engine [--mail [email protected]] [--options "opt=val"]... [--filter "filter"] [--host host] [--port port] [--userid bbunny --password c4rr0t5] [--ignore_channels KABC,KCBS,KNBC] qid
17
18 AutoSearch --VERSION
19 AutoSearch --help
20 AutoSearch --man
21
22 =cut
23
24 use Data::Dumper; # for debugging
25 use Date::Manip;
26 use File::Copy;
27 use Getopt::Long qw( :config no_ignore_case );
28 # use LWP::Debug qw(+ ); # -conns);
29 use Pod::Usage;
30 use POSIX qw(strftime);
31 use WWW::Search;
32
33 use strict;
34
35 use vars qw( $VERSION );
36 $VERSION = do { my @r = (q$Revision: 1.2 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r };
37
38 use constant DEBUG_EMAIL => 0;
39
40 my $TESTONLY = 0;
41
42 sub print_version
43 {
44 print STDERR "$0 version $VERSION; WWW::Search version $WWW::Search::VERSION\n";
45 } # print_version
46
47 my (%opts,@query_list,$query_name,$query_string,$search_engine,$query_options,$url_filter);
48 # Default options:
49 $opts{'m'} = '';
50 $opts{'cleanup'} = 0;
51 $opts{'cmdline'} = 0;
52 $opts{'emailfrom'} = '';
53 $opts{'v'} = 0;
54 $opts{'help'} = 0;
55 $opts{'man'} = 0;
56 $opts{'stats'} = 0;
57 $opts{'debug'} = 0;
58 $opts{'listnewurls'} = 0;
59 $opts{'ignore_channels'} = ();
60 &GetOptions(\%opts, qw(n|qn|queryname=s s|qs|querystring=s e|engine=s m|mail=s emailfrom=s host=s p|port=s o|options=s@ f|uf|urlfilter=s listnewurls stats userid=s password=s ignore_channels=s@ cleanup=i cmdline v|verbose help man V|VERSION debug),
61 'http_proxy=s',
62 'http_proxy_user=s',
63 'http_proxy_pwd=s',
64 ) or pod2usage(2);
65 if ($opts{'V'})
66 {
67 &print_version();
68 exit 0;
69 } # if
70 &pod2usage(1) if ($opts{'help'});
71 &pod2usage(
72 -verbose => 2,
73 ) if ($opts{'man'});
74 &pod2usage(
75 -verbose => 0,
76 -exitval => 1,
77 -message => 'missing argument "qid"',
78 ) if ($#ARGV == -1);
79
80 my $s_dbg = $opts{'stats'};
81 my $v_dbg = $opts{'v'};
82 my $d_dbg = $opts{'debug'} || $v_dbg;
83 if ($v_dbg)
84 {
85 print STDERR "v option: defined\n";
86 print STDERR "stats option: ", ! $opts{'stats'} ? 'not ' : '', "defined\n";
87 print STDERR "debug option: ", ! $opts{'debug'} ? 'not ' : '', "defined\n";
88 } # if
89 sub module_loaded
90 {
91 my $sModule = shift;
92 eval "use $sModule";
93 return ($@ eq '');
94 } # module_loaded
95 if ($opts{'m'} ne '')
96 {
97 MODULE:
98 foreach my $sMod (qw( Email::MIME Email::MIME::Creator Email::Send Email::Send::Sendmail Email::Send::Qmail Email::Send::SMTP ))
99 {
100 if (! &module_loaded($sMod))
101 {
102 print STDERR " --- can not load $sMod module: ==$@==\n";
103 $opts{'m'} = '';
104 last MODULE;
105 } # if
106 else
107 {
108 # print STDERR " + loaded $sMod\n";
109 }
110 } # foreach MODULE
111 } # if
112 print STDERR "will send email summary to: ", $opts{'m'}, "\n" if ($v_dbg && ($opts{'m'} ne ''));
113
114 # if we want a list of args:
115 #@query_list = split(/[,\s]+/, $opts{'n'},2) if defined($opts{'n'});
116
117 $query_name = $opts{'n'} || '';
118 $query_string = $opts{'s'} || '';
119 $search_engine = $opts{'e'} || '';
120 if (defined($opts{'o'}))
121 {
122 $query_options = {};
123 foreach my $sPair (@{$opts{'o'}})
124 {
125 my ($key, $value) = $sPair =~ m/^([^=]+)=(.*)$/;
126 &add_to_hash($key, &WWW::Search::escape_query($value), $query_options);
127 } # foreach
128 } # if
129 $url_filter = $opts{'f'} if defined($opts{'f'});
130 my($local_filter) = 0; # shall we exclude our own old pages? (1=y,0=n)
131
132 #print STDERR "n = \"$opts{'n'}\"\n" if defined($opts{'n'});
133 #print STDERR "s = \"$opts{'s'}\"\n" if defined($opts{'s'});
134 #print STDERR "e = \"$opts{'e'}\"\n" if defined($opts{'e'});
135 #print STDERR "o = \"$opts{'o'}\"\n" if defined($opts{'o'});
136 #print STDERR "f = \"$opts{'f'}\"\n" if defined($opts{'f'});
137
138 ##print STDERR "query_list = \"$query_list[0]\" \"$query_list[1]\"\n";
139 #print STDERR "query_name = \"$query_name\"\n";
140 #print STDERR "query_string = \"$query_string\"\n";
141 #print STDERR "search_engine = \"$search_engine\"\n";
142 #print STDERR "url_filter = \"$url_filter\"\n" if defined($opts{'f'});
143
144 &main(join(" ", @ARGV));
145
146 exit 0;
147
148 ########
149 # subs #
150 ########
151 #
152 # all the subroutine documentation has been disabled -- oh for a ifdef
153 # someday -- put all the subs in another file & tech documentation
154 # from there, man page from main file. wls :) 10/18/96 :(
155 #
156 #=head1 SUBROUTINES
157 #
158 #=cut
159 #
160 # Files expected first_date.html and first_index.html in the
161 # 'home' directory. These are used to build the initial
162 # search files.
163 #
164 # To start a new search: specify a query name (-qn) and
165 # query string (-qs) (and more). If either are not provided, AS will
166 # ask the user (STDIN) for the name and/or the string as necessary.
167 # The string "AutoSearch WEB Searching" is replaced by the query name
168 # and the string "ask user" is replaced by the query string.
169 #
170 # AS 1.x accepts the basic query sub-directory identifier
171 # and looks to see if qid/date.html exists. If this file
172 # file does not exist, AS looks for a file first_date.html
173 # If the default file in the parent directory is missing, AS
174 # creates a default-default file named qid/date.html.
175 # In any case the directory 'qid' is created.
176 # A second file first_index.html is used to create the initial
177 # qid/index.html file in a like fashon.
178 #
179 # (LATER: ADD SEARCH ENGINE(S))
180 # There are three important items which must be defined for any
181 # search that AS will process. First the query-subdirectory
182 # identifier (qid). This is the handle to this query.
183 # Once a query session is established; only the qid need be
184 # specified on the command line.
185 # Second is the 'pretty name' that you will assign to this
186 # Query. This is used at the top of the screens to help
187 # the user identify what the searche topic is. Third
188 # is the actual search string. This is passed directly to
189 # search processor, and the search engine.
190 #
191 # File date.html is used to define the format of the pages which are
192 # created each time (weekly) AutoSearch.pl is run. Major sections of
193 # the file are identified with html comments. The search string is
194 # embedded in this file too. One method of creating a new search is
195 # to create the new directory manually and create a file named
196 # date.html in the sub-directory. However; this requires you to
197 # understand the tags and build a file which is compatible with AS.
198 #
199 # A second method is to manually copy first_date.html to qid/date.html
200 # and edit it. This is the John method to introduce a new search. It
201 # is cumbersome and not-automated-ish.
202 #
203 # A third approach involves using command line arguments to specify
204 # the query name and string. This is the wls method. One variation
205 # on the wls method is the "ask user" method. In this approach, AS
206 # will ask the user for the required items. In both of these methods
207 # the necessary files will be created.
208 #
209 # Once the initial search has been made and the files created, then
210 # the simple command "AutoSearch qid" will update the search files and
211 # pages.
212 #
213 #=head1 NAME
214 #
215 #main - start of actual work.
216 #
217 #
218 #=head1 DESCRIPTION
219 #
220 #Submit a search and build output files.
221 #
222 #=cut
223
224 # submit a search and optionally build output file(s).
225 #
226 sub main
227 {
228 my ($query_dir) = @_;
229 my $dbg_search = $d_dbg || 0;
230 my $v_dbg = $v_dbg; # shall we be verbose??
231 my $sEmail = '';
232 my $url_filter_count = 0;
233 # get the date.
234 my $now = &time_now;
235 my $today = &time_today;
236 print STDERR "Now = ", $now if $v_dbg;
237 print STDERR ", Today = ", $today, "\n" if $v_dbg;
238 # Build query directory string:
239 my $qid = $query_dir;
240 die ("qid is a required argument.") unless ($qid);
241 die ("qid is a required argument.") unless ($qid =~ m!\S!);
242 print STDERR "query directory: $qid\n" if $v_dbg;
243 # Do we have the necessary infrastructure? We require two files: 1)
244 # the summary of searches and 2) weekly updates. Look for
245 # index.html, or default first_index.html, or make one from scratch.
246 # index.html contains the previous search results. (aka old summary)
247 &check_index_file($qid); # make qid/index.html
248 $v_dbg && print STDERR " + found/created $qid/index.html\n";
249 if ($opts{'cmdline'})
250 {
251 # Show the original cmdline and exit:
252 my %hssOptions = (
253 Query => '--querystring',
254 QueryName => '--queryname',
255 SearchEngine => '--engine',
256 URLFilter => '--filter',
257 QueryOptions => '--option',
258 # IgnoreChannels => '--ignore_channels',
259 );
260 my $sFile = qq{$qid/index.html};
261 open(INDEX, $sFile) or die " --- can not open $sFile for read: $!";
262 # Slurp entire file:
263 local $/ = undef;
264 my $sHTML = <INDEX>;
265 close(INDEX) or warn " --- can not close $sFile after reading: $!";
266 my $sCmdline = qq{$0 $qid };
267 # Special case: look for QueryName inside <h1> tags:
268 $sHTML =~ s#<h1>(.+?)</h1>#<!--QueryName\{$1}/QueryName-->#;
269 while (my ($sTag, $sArg) = each %hssOptions)
270 {
271 while ($sHTML =~ m#<!--$sTag\{(.*?)}/$sTag-->#g)
272 {
273 my $sValue = $1 || '';
274 $sCmdline .= qq{$sArg "$sValue" } if ($sValue ne '');
275 } # while
276 } # while
277 print STDERR "\n$sCmdline\n";
278 return;
279 } # if --cmdline
280
281 my $iCleanup = $opts{'cleanup'};
282 if (0 < $iCleanup)
283 {
284 print STDERR " + doing cleanup $iCleanup in ==$qid==\n" if $opts{debug};
285 # We don't care what the timezone is, we only deal with days:
286 &Date_Init('TZ=US/Eastern');
287 my $dateCutoff = &DateCalc('today', " - $iCleanup days");
288 my $sCutoff = &UnixDate($dateCutoff, '%Y%m%d');
289 print STDERR " + cutoff date is ==$sCutoff==\n" if $opts{debug};
290 opendir(DIR, $qid) or die(" --- can not read directory $qid: $!");
291 CLEANUP_FILE:
292 while (my $sFile = readdir(DIR))
293 {
294 next CLEANUP_FILE if $sFile eq '.';
295 next CLEANUP_FILE if $sFile eq '..';
296 print STDERR " + found file ==$sFile==\n" if $opts{debug};
297 if ($sFile lt $sCutoff)
298 {
299 print STDERR " + unlink ==$sFile==\n" if $opts{debug};
300 unlink qq{$qid/$sFile} or warn $!;
301 } # if file is old
302 } # while
303 closedir DIR;
304 # Now delete old lines from index.html:
305 my $sFile = qq{$qid/index.html};
306 my $sFileNew = qq{$sFile.new};
307 open(INDEX, $sFile) or die " --- can not open $sFile for read: $!";
308 open(NEW, '>'. $sFileNew) or die " --- can not open $sFileNew for write: $!";
309 local $/ = "\n";
310 CLEANUP_LINE:
311 while (my $sLine = <INDEX>)
312 {
313 if ($sLine =~ m!search on ([A-Za-z]+ \d+, \d+)!)
314 {
315 # This line contains a date.
316 my $date = &ParseDate($1);
317 my $iCmp = &Date_Cmp($date, $dateCutoff);
318 if ($iCmp < 0)
319 {
320 # This line's date is before the cutoff.
321 print STDERR " + delete line $sLine" if $opts{debug};
322 next CLEANUP_LINE;
323 } # if
324 } # if
325 print NEW $sLine;
326 } # while
327 close INDEX;
328 close NEW;
329 copy($sFileNew, $sFile) or die " --- can not copy $sFileNew to $sFile: $!";
330 unlink $sFileNew; # No big deal if this fails
331 # All done:
332 return;
333 } # if --cleanup
334
335 $qid .= '/' unless substr($qid,-1,1) eq '/'; # we MUST have a /
336 # Read index.html and break into fields.
337 my ($SummaryTop, $SummaryQuery,
338 $SummarySearchEngine, $SummaryURLFilter,
339 $SummaryHeading, $SummaryTemplate, $Summary,
340 $WeeklyHeading, $WeeklyTemplate, $Weekly,
341 $SummaryBottom, @SummaryQueryOptions) = &get_summary_parts($qid);
342 $v_dbg && print STDERR " + got summary parts...\n";
343 # Split the old summary into a list. (later sort it)
344 my ($url, $description, $title);
345 my (@old_summary_url,@old_summary_title);
346 my @old_summary = split(/\n/,$Summary);
347 my ($line);
348 my ($i, $n, $j, $m);
349 # Break each hyperlink into its url and title.
350 for my $i (0..$#old_summary)
351 {
352 # $old_summary -> $url & $title
353 $line = $old_summary[$i];
354 if ($line =~ m#<a href="(.*)">(.*)</a><br>#i)
355 {
356 $url = $1;
357 $title = $2;
358 push (@old_summary_url,$url);
359 push (@old_summary_title,$title);
360 } # if
361 } # for
362
363 # For each item in weekly list:
364 # If it is in old summary list remove it, else leave it.
365 # Hint: note alphabetical order to reduce searching.
366 # Append weekly list to summary list. Sort it.
367 # Use summary list to build a new summary.
368 # Output first half of the NEW index.html page. (summary)
369 # Append either "no new results" (if zero unique left in weekly list)
370 # or the date to weekly results list.
371 # Output second half of NEW index.html page. (weekly results)
372 #
373 # If non-zero, use weekly list to build weekly file.
374
375 # These are the input params to autosearch:
376 # 1) qid, 2) query name, 3) query string, 4) search engine,
377 # 5) query options, and 6) url filter RE.
378 # Dispose of input params as follows:
379 # Insert the Query Name into 'Top' for index.html & date.html,
380 # Insert the Query String, Search Engine, and URL Filter into
381 # the 'HTML fields' from index.html
382 # Precedence of input: Query Name (pretty name) and Query String (search engine)
383 # Search Engine (AltaVista), Search Options (## need example ##),
384 # URL Filter (to suppress display and tracking of particular URLs)
385 # 1) from existing file or default files (files already in place), or
386 # 2) from user.
387 # (either a) command line or b) "ask user" (or error if we don't dare))
388 my ($QueryName, $QueryString, $SearchEngine, $URLFilter);
389 $QueryName = $query_name;
390 # did we get a Query Name/String/Engine/Options/Filter from existing files?
391 if ($SummaryTop =~ m/AutoSearch WEB Searching/i)
392 {
393 if ($query_name eq '')
394 {
395 # We did not get --queryname from command line
396 $QueryName = &read_query("Please enter a Query Name:");
397 } # if
398 $SummaryTop =~ s/AutoSearch WEB Searching/$QueryName/i;
399 } # if
400 print STDERR "Query Name is \"$QueryName\"\n" if $v_dbg;
401
402 if ($SummaryQuery =~ m/ask user/i)
403 {
404 if ($query_string ne '')
405 {
406 # We did get --querystring from command line
407 $QueryString = $query_string;
408 }
409 else
410 {
411 # We did NOT get --querystring, ask the user:
412 $QueryString = &read_query("Please enter a Query String:");
413 }
414 $SummaryQuery =~ s/ask user/$QueryString/i;
415 print STDERR "Query String is \"$QueryString\"\n" if $v_dbg;
416 } # if
417 my $sTitle = "<Title> Search results for $SummaryQuery as of $now </Title>\n";
418
419 # This is not a required field.
420 # This MUST BE 'ask user' to get AutoSearch to ask.
421 if ($SummarySearchEngine =~ m/ask user/i)
422 {
423 if ($search_engine ne '')
424 {
425 # We DID get --engine on command line:
426 $SearchEngine = $search_engine;
427 }
428 else
429 {
430 # We did NOT get --engine, ask user:
431 $SearchEngine = &read_query("Please enter a Search Engine:");
432 }
433 $SummarySearchEngine =~ s/ask user/$SearchEngine/i;
434 }
435 else
436 {
437 # don't ask; try command line:
438 if ($search_engine ne '')
439 {
440 # We DID get --engine on command line:
441 $SearchEngine = $search_engine;
442 }
443 else
444 {
445 # No --engine on command line, no Search Engine in index file.
446 # Use whatever was in the first_index.html file
447 $SearchEngine = $SummarySearchEngine;
448 }
449 $SummarySearchEngine = $SearchEngine;
450 }
451 print STDERR "Search Engine is \"$SearchEngine\"\n" if $v_dbg;
452
453 # This is not a required field.
454 # This MUST BE 'ask user' to get AutoSearch to ask.
455 #
456 # print $SummaryQueryOptions[0], " v. ask user\n";
457 if ($SummaryQueryOptions[0] =~ m/ask user/i) { # either ask or use command line
458 # print $SummaryQueryOptions[0], " is ask user\n";
459 if (defined($opts{'o'})) { # from command line ?
460 # print STDERR "defined.\n";
461 # use $query_options
462 } else { # no, ask 'em
463 # print STDERR "not defined.\n";
464 @SummaryQueryOptions = &read_query_list("Please enter Query Options:");
465 $query_options = {};
466 foreach (@SummaryQueryOptions) {
467 next if m/^$/;
468 my($key, $value) = m/^([^=]+)=(.*)$/;
469 # print STDERR "option:$_ is $key=$value\n";
470 &add_to_hash($key, &WWW::Search::escape_query($value), $query_options);
471 }
472 }
473 } else { # or use what came from index.html file
474 $query_options = {};
475 foreach (@SummaryQueryOptions) {
476 next if m/^$/;
477 my($key, $value) = m/^([^=]+)=(.*)$/;
478 # print STDERR "option:$_ is $key=$value\n";
479 &add_to_hash($key, &WWW::Search::escape_query($value), $query_options);
480 }
481 }
482
483 # this is not a required field.
484 # this MUST BE ask user to get AutoSearch to ask.
485 if ($SummaryURLFilter =~ m/ask user/i) { # no, shall we ask the user
486 if (defined($url_filter)) { # from command line ?
487 $URLFilter = $url_filter;
488 } else { # no, ask 'em
489 $URLFilter = &read_query("Please enter a URL Filter:");
490 }
491 $SummaryURLFilter =~ s/ask user/$URLFilter/i;
492 } else { # don't ask; try command line
493 if (defined($url_filter)) { # from command line ?
494 $URLFilter = $url_filter; # yes
495 } else { # if no comamnd line, no filter!!
496 $URLFilter = $SummaryURLFilter; # use whatever was in the first_index.html file
497 }
498 $SummaryURLFilter = $URLFilter;
499 }
500 if ($s_dbg)
501 {
502 print STDERR qq{Query is : "$SummaryQuery"};
503 print STDERR qq{ with "@SummaryQueryOptions"} if ($#SummaryQueryOptions);
504 print STDERR "\n";
505 } # if
506 print STDERR "URL Filter is \"$URLFilter\"\n" if $v_dbg;
507 #
508 # now locate the weekly format file.
509 # 1) qid/date.html, or 2) first_date.html, or 3) create one.
510 &check_date_file($qid,$QueryName,$QueryString); #make qid/date.html
511
512 # read date.html and break into fields.
513 # make the search results into a list of urls, title, & descr).
514 # (later sort it)
515 # note: Top & Bottom CAN BE different from index.html.
516 my($WeeklyTop,
517 $AppendedHeading,$AppendedTemplate,$Appended,
518 $SuspendedHeading,$SuspendedTemplate,$Suspended,
519 $WeeklyBottom)
520 = &get_weekly_parts($qid);
521 # insert queryname into html Top from date.html
522 # usually this is not set up, because when we created the file we didn't
523 # have the data. Do we have the Query Name?
524 $WeeklyTop =~ s/>AutoSearch WEB Searching</$QueryName/;
525 $v_dbg && print STDERR " + got weekly parts...\n";
526
527 my $hits = 0; # actual no. of hits.
528 my $saved = 0; # actual no. saved.
529 my $search;
530 # Search AltaVista, or whatever the user has specified.
531 if($SummarySearchEngine) {
532 $search = new WWW::Search($SummarySearchEngine);
533 } else {
534 $search = new WWW::Search(undef()); # must be undef to get default.
535 }
536 $search->{_host} = $opts{'h'} if defined($opts{'h'});
537 $search->{_port} = $opts{'p'} if defined($opts{'p'});
538 if (defined($opts{'http_proxy'}) && ($opts{'http_proxy'} ne ''))
539 {
540 print STDERR qq{ + applying http_proxy }, Dumper(\$opts{http_proxy}) if $opts{'debug'};
541 $search->http_proxy(['http', ] => $opts{'http_proxy'});
542 if (defined($opts{'http_proxy_user'}) && ($opts{'http_proxy_user'} ne ''))
543 {
544 print STDERR qq{ + applying $opts{http_proxy_user}...\n} if $opts{'debug'};
545 $search->http_proxy_user($opts{'http_proxy_user'});
546 $search->http_proxy_pwd($opts{'http_proxy_pwd'});
547 } # if
548 } # if
549 elsif ($opts{'env_proxy'})
550 {
551 $search->env_proxy($opts{'env_proxy'});
552 }
553 elsif (0)
554 {
555 # This is the OLD code:
556 $search->http_proxy($ENV{'HTTP_PROXY'}) if ($ENV{'HTTP_PROXY'});
557 $search->http_proxy($ENV{'http_proxy'}) if ($ENV{'http_proxy'});
558 } # if
559 # submit search w/options.
560 $search->native_query(WWW::Search::escape_query($SummaryQuery), $query_options);
561 $search->login($opts{'userid'}, $opts{'password'});
562 # Process the --ignore_channels argument(s):
563 my @asChannel;
564 foreach my $sChannel (@{$opts{'ignore_channels'}})
565 {
566 push @asChannel, split(/,/, $sChannel);
567 } # foreach
568 if ($search->can('ignore_channels')
569 &&
570 scalar(@asChannel)
571 )
572 {
573 $search->ignore_channels(@asChannel);
574 } # if
575 # examine search results
576 my($next_result);
577 my(@new_weekly_url,@new_weekly_title,@new_weekly_description);
578 my @aoResult; # Parallel array to new_weekly_url
579 my(@weekly_url,@weekly_title);
580
581 # care to see the old summary list?
582 # print STDERR "old summary:\n";
583 # foreach $line (@old_summary_url) {
584 # print STDERR "$line\n";
585 # }
586
587 # how many hits?
588 # convert latest search results to a list of urls (descriptions & titles)
589 # filtered by $SummaryURLFilter called new_weekly_*
590 NEXT_URL:
591 while ($next_result = $search->next_result()) { # page-by-page
592 $url = $next_result->url;
593 $hits++; # how many were returned?
594 if ($local_filter) { # exclude old pages from prev. version?
595 # let's not display references to our own pages.
596 next if $url =~ m,www\.isi\.edu/div7/ib/(.+)/(\d+)\.html$,o;
597 # let's not display references to our old pages.
598 next if $url =~ m,www\.isi\.edu/div7/ib/jog,o;
599 }
600 # let the user filter out URLs.
601 if ( ($SummaryURLFilter) && ($url =~ m,$SummaryURLFilter,oi) ) {
602 # print STDERR "filter out $url \n with filter: $SummaryURLFilter\n";
603 $url_filter_count++;
604 next;
605 }
606 $saved++; # how many were saved?
607 push(@weekly_url,$url); # the complete set of hits
608 $title = $next_result->title;
609 push(@weekly_title,$title);
610 # Was it in the old summary? If so, don't save it.
611 # If not, it is a new search results for this week.
612 foreach $line (@old_summary_url)
613 {
614 # See if this url is in the summary; skip this url if it's in
615 # the summary:
616 next NEXT_URL if ($url eq $line);
617 } # foreach
618 print STDERR "url:$url ** new result **\n" if $dbg_search;
619 print "$url\n" if $opts{'listnewurls'};
620 $description = $next_result->description;
621 print STDERR "description: ", $description, "\n" if $dbg_search;
622 print STDERR "title: ", $title, "\n" if $dbg_search;
623 push(@new_weekly_url,$url); # the newest set of hits (added)
624 push(@new_weekly_description,$description);
625 push(@new_weekly_title,$title);
626 push @aoResult, $next_result;
627 } # while NEXT_URL
628 # Report errors, if any:
629 my $response = $search->response();
630 if ($response->is_success)
631 {
632 if ($hits == 0)
633 {
634 print STDERR "Warning: Empty results set.\n" if ($v_dbg);
635 } # if no hits
636 } # if HTTP success
637 else
638 {
639 my $sMsg = "Error: " . http_error_as_nice_string($response);
640 print STDERR "$sMsg\n";
641 $sEmail .= "$sMsg\n";
642 } # else HTTP error
643
644 # Only save the ones that don't show up in the current query list.
645 # Those we shall call suspended_*
646 my (@suspended_url,@suspended_title);
647 # We must use a for loop, to get the urls to match their descr &
648 # title.
649 OLD_URL:
650 for my $i (0..$#old_summary_url)
651 {
652 $url = $old_summary_url[$i];
653 for my $j (0..$#weekly_url)
654 {
655 $line = $weekly_url[$j];
656 # if we match the weekly (active search) hits, skip it.
657 next OLD_URL if $url eq $line;
658 } # for $j
659 printf STDERR "suspend: [%02d]%s\n",$i,$url if $dbg_search;
660 # not found? save it, it's been suspended
661 push(@suspended_url,$url);
662 $title = $old_summary_title[$i];
663 push(@suspended_title,$title);
664 } # for $i
665 # stats?? (to see 'em use -stats)
666 print STDERR "old summary count: ",$#old_summary_url + 1,"\n" if ($s_dbg);
667 print STDERR "new raw hits : ",$hits,"\n" if ($s_dbg);
668 print STDERR "urls filtered : ",$url_filter_count,", filter \"",$URLFilter,"\"\n" if ($s_dbg);
669 print STDERR "not filtered : ",$saved,"\n" if ($s_dbg);
670 print STDERR "results set count: ",$#new_weekly_url + 1,"\n" if ($s_dbg);
671 print STDERR "suspended count : ",$#suspended_url + 1,"\n" if ($s_dbg);
672 print STDERR "final count : ",$#weekly_url + 1,"\n" if ($s_dbg);
673 my $changes = (($#new_weekly_url != -1) || ($#suspended_url != -1));
674 # printf STDERR "changes is %d\n",$changes if ($v_dbg);
675
676 # For every search, AutoSearch (aka AS) will make a 'weekly' file.
677 # Usually AutoSearch is run as a 'cron' job; but can be run manually.
678 # AS will attempt to handle multiple (non-concurrent) runs per day.
679 my $file = (&time_file_of_the_day_numeric).'.html';
680 my $section;
681 my $junk;
682 # to test this 'diff' code 1) rm -r qid/* 2) run AS -stats qid -qn -qs
683 # 3) edit qid/index.html remove some, add some (new urls)
684 # 4) run AS -stats qid; look at <today>.html
685 # you will see 'deleted' (from above) as 'recently added' &
686 # 'added' (from above) as 'recently suspended'
687 # reason: the changes were forced in 'old summary',
688 # usually (normal, non-testing cases) the changes will appear in new_weekly_*
689 # now if this is a run that adds information (re) write the file.
690 #
691 # do we have a reason to care? New Results, Appensions, Suspensions???
692 my $iNewResultCount = 0;
693 if ($changes)
694 {
695 # print STDERR "test file: $qid$file\n";
696 if (-e $qid.$file)
697 {
698 # File already exists; modify it.
699 print STDERR "modify existing weekly file.\n" if ($v_dbg);
700 # Copy in previous file from today:
701 open (PARTS,'<'.$qid.$file) || die "Can't open weekly input file.\nReason: $!\n";
702 my($part) = <PARTS>;
703 close (PARTS);
704 # print STDERR "Part:\"$part\"\n";
705 # break into parts to insert modifications
706 my($part1,$part2) = split (/<!--\/Appended-->/,$part,2);
707 my($part3,$part4) = split (/<!--\/Suspended-->/,$part2,2);
708 # write back out w/ changes.
709 open (HTML,'>'.$qid.$file) || die "Can't open weekly output file.\nReason: $!\n";
710 print HTML $part1;
711 $n = $#new_weekly_url + 1;
712 if ($n) {
713 print HTML "<!--more...-->\n";
714 print HTML "<h4>Recently Added:</h4><p>\n";
715 }
716 # format each unique result.
717 for ($i=0; $i < $n; $i++) {
718 $url = $new_weekly_url[$i];
719 $title = $new_weekly_title[$i];
720 $description = $new_weekly_description[$i];
721 my $sHTMLlink = &make_link($AppendedTemplate, $url, $title, $description);
722 print HTML "$sHTMLlink\n";
723 # print STDERR " DDD search is $search\n";
724 $sEmail .= q{<P>}. $search->result_as_HTML($aoResult[$i], '%Y-%m-%d %H:%M %Z');
725 } # for
726 print HTML "<!--/Appended-->"; # replace due to split
727 print HTML $part3;
728 $n = $#suspended_url + 1;
729 if ($n) {
730 print HTML "<!--less...-->\n";
731 print HTML "<h4>Recently Suspended:</h4><p>\n";
732 }
733 # format each suspended result.
734 for ($i=0; $i < $n; $i++) {
735 $url = $suspended_url[$i];
736 $title = $suspended_title[$i];
737 print HTML &make_link($SuspendedTemplate,$url,$title,""),"\n";
738 }
739 print HTML "<!--/Suspended-->"; # replace due to split
740 print HTML $part4;
741 close (HTML);
742 }
743 else
744 { # create the file
745 # print STDERR "make new weekly file.\n" if ($v_dbg);
746 open (HTML,'>'.$qid.$file) || die "Can't open weekly output file.\nReason: $!\n";
747 print HTML $sTitle;
748 print HTML "<!-- created by AutoSearch.pl by wls -->\n";
749 print HTML "<!--Top-->\n$WeeklyTop<!--/Top-->\n";
750 DEBUG_EMAIL && print STDERR " + start creating email, new_weekly_url is ", Dumper(\@new_weekly_url);
751 # Output weekly search status: appended
752 $iNewResultCount = $#new_weekly_url + 1;
753 # Always do the header:
754 print HTML "<!--AppendedHeading\n$AppendedHeading/AppendedHeading-->\n";
755 print HTML &format_link($AppendedHeading,"DATE", $now) if $iNewResultCount;
756 print HTML "<!--AppendedTemplate\n$AppendedTemplate/AppendedTemplate-->\n";
757 $section = "Appended"; # the section of the file/output.
758 print HTML "<!--$section-->\n";
759 # Format each unique result:
760 for my $i (0..$iNewResultCount-1)
761 {
762 $url = $new_weekly_url[$i];
763 $title = $new_weekly_title[$i];
764 $description = $new_weekly_description[$i];
765 my $sHTMLlink = &make_link($AppendedTemplate, $url, $title, $description);
766 print HTML "$sHTMLlink\n";
767 $sEmail .= q{<P>}. $search->result_as_HTML($aoResult[$i], '%Y-%m-%d %H:%M %Z');
768 } # for $i
769 print HTML $Appended;
770 print HTML "<!--/$section-->\n\n";
771
772 # output weekly search status: suspended
773 $n = $#suspended_url + 1;
774 # always do the heading
775 print HTML "<!--SuspendedHeading\n$SuspendedHeading/SuspendedHeading-->\n";
776 print HTML &format_link($SuspendedHeading,"DATE","$now") if $n;
777 print HTML "<!--SuspendedTemplate\n$SuspendedTemplate/SuspendedTemplate-->\n";
778 $section = "Suspended"; # the section of the file/output.
779 print HTML "<!--$section-->\n";
780 for ($i=0; $i < $n; $i++) {
781 $url = $suspended_url[$i];
782 $title = $suspended_title[$i];
783 print HTML &make_link($SuspendedTemplate,$url,$title,""),"\n";
784 } # for $i
785 print HTML $Suspended;
786 print HTML "<!--/$section-->\n\n";
787 print HTML "<!--Bottom-->\n$WeeklyBottom<!--/Bottom-->\n";
788 close (HTML);
789 } # else daily file doesn't exist
790 } # if any new hits
791 else
792 {
793 print STDERR "no weekly changes required.\n" if ($v_dbg);
794 }
795 $QueryName = $SummaryQuery if ($QueryName eq '');
796 # Now write the new index file.
797 # Create the index.html output file:
798 open (HTML,'>'.$qid.'index.html') || die "Can't open summary output file.\nReason: $!\n";
799 print HTML "<Title> Summary of Search results for $SummaryQuery</Title>\n";
800 print HTML "<!-- created by AutoSearch.pl by wls -->\n";
801 print HTML "<!--Top-->\n$SummaryTop<!--/Top-->\n";
802 print HTML "<!--Query{$SummaryQuery}/Query-->\n";
803 print HTML "<!--QueryName{$QueryName}/QueryName-->\n";
804 print HTML "<!--SearchEngine{$SummarySearchEngine}/SearchEngine-->\n" if ($SummarySearchEngine);
805 print HTML "<!--URLFilter{$SummaryURLFilter}/URLFilter-->\n" if ($SummaryURLFilter);
806 foreach my $key (keys (%{$query_options})) {
807 # print STDERR "option::$key=$query_options->{$key}\n";
808 print HTML "<!--QueryOptions{$key\=$query_options->{$key}\}QueryOptions-->\n";
809 }
810 # output summary of updated unique findings
811 print HTML "<!--SummaryHeading\n$SummaryHeading/SummaryHeading-->\n";
812 print HTML &format_link($SummaryHeading, "DATE", $now);
813 print HTML "<!--SummaryTemplate\n$SummaryTemplate/SummaryTemplate-->\n";
814 $section = "Summary"; # the section of the file/output.
815 print HTML "<!--$section-->\n";
816 if ($#new_weekly_url < 0) { # it has't changed; just re-cycle it.
817 print HTML $Summary;
818 } else {
819 # format each unique result.
820 # $description = "";
821 $n = $#weekly_url + 1;
822 for ($i=0; $i < $n; $i++) {
823 $url = $weekly_url[$i];
824 $title = $weekly_title[$i];
825 print HTML &make_link($SummaryTemplate,$url,$title,""),"\n";
826 }
827 }
828 # Output daily results status (none or ptr to new file).
829 print HTML "<!--/$section-->\n\n";
830 print HTML "<!--WeeklyHeading\n$WeeklyHeading/WeeklyHeading-->\n";
831 print HTML &format_link($WeeklyHeading,"DATE", $now);
832 print HTML "<!--WeeklyTemplate\n$WeeklyTemplate/WeeklyTemplate-->\n";
833 $section = "Weekly"; # the section of the file/output.
834 print HTML "<!--$section-->\n";
835 # report errors FIRST.
836 if ($hits == 0)
837 {
838 my($response) = $search->response();
839 if ($response->is_success)
840 { # dbg message, normally we're quiet
841 # print HTML "AutoSearch Warning: Empty Results Set. <br>\n";
842 }
843 else
844 { # SearchEngine error message:
845 my $sMsg = "AutoSearch Error during search on $today: " . http_error_as_nice_string($response);
846 print HTML "$sMsg<br>\n";
847 $sEmail .= "$sMsg\n";
848 }
849 } # if no hits
850 # Let's use reverse chronological order.
851 # Update the 'weekly' status:
852 if ($changes)
853 { # there were changes.
854 # second run today?
855 if ($Weekly =~ m/^No unique results found for(.*)$today/i)
856 {
857 # print STDERR "change 'No' to 'Yes'\n";
858 # The first line SHOULD be today's, assume so.
859 # Delete first line of $Weekly and write new link:
860 ($junk, $Weekly) = split (/\n/,$Weekly,2); # split off first line
861 print HTML "Web search results for <a href=\"$file\">search on ",$today,"</a><br>\n";
862 }
863 elsif ($Weekly =~ m/^AutoSearch Error during search on $today/i)
864 {
865 # print STDERR "change 'Error' to 'Yes'\n";
866 # The first line SHOULD be today's, assume so.
867 # Delete first line of $Weekly and write new link:
868 ($junk, $Weekly) = split(/\n/, $Weekly, 2); # split off first line
869 print HTML "Web search results for <a href=\"$file\">search on ",$today,"</a><br>\n";
870 }
871 elsif ($Weekly =~ m/^Web search results for(.*)$today/)
872 { # yes we already have a link, leave it.
873 # print STDERR "leave 'Yes'\n";
874 }
875 else
876 { # no link for today of any kind. add one.
877 # print STDERR "insert 'Yes'\n";
878 print HTML "Web search results for <a href=\"$file\">search on ",$today,"</a><br>\n";
879 }
880 } # there were any $changes
881 else
882 {
883 # second run today?
884 if ($Weekly =~ m/^No unique results found for(.*)$today/i)
885 {
886 # print STDERR "leave 'No'\n";
887 }
888 elsif ($Weekly =~ m/^AutoSearch Error during search on $today/i)
889 {
890 # print STDERR "change 'Error' to 'No'\n";
891 # The first line SHOULD be today's, assume so.
892 # Delete first line of $Weekly and write new link:
893 ($junk, $Weekly) = split(/\n/, $Weekly, 2); # split off first line
894 print HTML "No unique results found for search on ",$today,"<br>\n";
895 }
896 elsif ($Weekly =~ m/^Web search results for(.*)$today/)
897 { # We found results earlier today, leave them.
898 # print STDERR "leave 'Yes'\n";
899 }
900 else
901 {
902 # print STDERR "insert 'No'\n";
903 print HTML "No unique results found for search on ",$today,"<br>\n";
904 }
905 } # there were no $changes
906 print HTML $Weekly;
907 print HTML "<!--/$section-->\n\n";
908
909 print HTML "<!--Bottom-->\n$SummaryBottom<!--/Bottom-->\n";
910 close (HTML);
911
912 # DEBUG_EMAIL && print STDERR " + opts{m} =$opts{m}=\n";
913 # DEBUG_EMAIL && print " + raw sEmail =====$sEmail=====\n";
914 if (($opts{'m'} ne '') && ($sEmail ne ''))
915 {
916 $sEmail = <<"EMAILEND";
917 <HTML>
918 <HEAD>$sTitle</HEAD>
919 <BODY>
920 <h2>The following $iNewResultCount URLs are new matches for your $SummarySearchEngine query '$SummaryQuery':</h2>
921 $sEmail
922 </BODY></HTML>
923 EMAILEND
924 # DEBUG_EMAIL && print STDERR " + cooked sEmail =====$sEmail=====\n";
925 # DEBUG_EMAIL && exit 88;
926 my $sSubject = "Results of AutoSearch query '$SummaryQuery'";
927 my $sFrom = 'AutoSearch@localhost';
928 $sFrom = $opts{emailfrom} if ($opts{emailfrom} ne '');
929 my $oMsg = Email::MIME->create(
930 header => [
931 To => $opts{'m'},
932 Subject => $sSubject,
933 From => $sFrom,
934 ],
935 attributes => {
936 'content_type' => 'text/html',
937 },
938 body => $sEmail,
939 );
940 DEBUG_EMAIL && print STDERR " + oMsg is ", Dumper($oMsg);
941 if (ref($oMsg))
942 {
943 DEBUG_EMAIL && print STDERR " + oMsg in sendable format is:\n";
944 DEBUG_EMAIL && Email::Send::send(IO => $oMsg);
945 my $sRes = &send_email($oMsg);
946 print STDERR "result of send_email() is ==$sRes=\n" if ($v_dbg || ($sRes ne '1'));
947 # print STDERR $sRes if ($v_dbg || ($sRes ne '1'));
948 }
949 else
950 {
951 print STDERR " --- could not create Email::MIME object\n";
952 }
953 } # if
954 } # main
955
956 sub send_email
957 {
958 my $oMessage = shift;
959 my $sSMTPserver = $ENV{SMTPSERVER} || shift || '';
960 if ($sSMTPserver ne '')
961 {
962 my $sUsername = $ENV{SMTPUSERNAME} || shift || '';
963 my $sPassword = $ENV{SMTPPASSWORD} || shift || '';
964 if ($TESTONLY)
965 {
966 $sUsername = '<empty>' if ($sUsername eq '');
967 $sPassword = ($sPassword eq '') ? '<empty>' : '<hidden>';
968 return qq{$0 chose method SMTP::Auth with server=$sSMTPserver, username=$sUsername, password=$sPassword};
969 } # if
970 return Email::Send::SMTP->send($oMessage,
971 Host => $sSMTPserver,
972 username => $sUsername,
973 password => $sPassword,
974 );
975 } # if SMTP
976 if (
977 # User has customized the pointer to the qmail program:
978 ($Email::Send::Qmail::QMAIL ne 'qmail-inject')
979 ||
980 # I hate that "used only once" warning:
981 ($Email::Send::Qmail::QMAIL ne 'qmail-inject')
982 # HOW else do we indicate in the environment that we want to use
983 # Qmail?
984 )
985 {
986 if ($TESTONLY)
987 {
988 return qq{$0 chose method Qmail};
989 } # if
990 return Email::Send::Qmail::send($oMessage, @_);
991 } # if qmail
992 # For undef warnings:
993 $ENV{SENDMAIL} ||= '';
994 if (
995 ($^O =~ m!solaris!i) # A fair assumption?
996 ||
997 ($^O =~ m!linux!i) # A fair assumption?
998 )
999 {
1000 # User has customized the pointer to the sendmail program:
1001 if ($ENV{SENDMAIL} ne '')
1002 {
1003 $Email::Send::Sendmail::SENDMAIL = $Email::Send::Sendmail::SENDMAIL = $ENV{SENDMAIL};
1004 } # if
1005 if ($TESTONLY)
1006 {
1007 return qq{$0 chose method Sendmail};
1008 } # if
1009 return Email::Send::Sendmail::send($oMessage, @_);
1010 } # if solaris or linux
1011 return "Error: can not determine email send method\n";
1012 } # send_email
1013
1014
1015 #=head1 NAME
1016 #
1017 #check_index_file($qid) - insure the index.html file exists.
1018 #
1019 #
1020 #=head1 DESCRIPTION
1021 #
1022 #If qid/index.html exists just return.
1023 #Else create qid/ if necessary and call make_index
1024 #to make the F<index.html> file.
1025 #
1026 #=cut
1027
1028 sub check_index_file {
1029 my ($qid) = @_;
1030 # do we have the necessary infrastructure?
1031 if (open (FIRST,"<$qid/index.html") ) { # yes
1032 # OK, close it.
1033 close (FIRST);
1034 } else { # no, make dir.
1035 if (mkdir ($qid, 0755) ) {
1036 if ($! =~ m/file exists/i) { # already done
1037 die "Can't create directory $qid.\nReason $!";
1038 }
1039 }
1040 chmod 0755, $qid || die "Can't chmod directory $qid.\nReason $!";
1041 &make_index($qid);
1042 }
1043 print STDERR "index.html exists, " if $main::v_dbg;
1044 } # check_index_file
1045
1046 #=head1 NAME
1047 #
1048 #check_date_file($qid) - insure the date.html file exists.
1049 #
1050 #=head1 DESCRIPTION
1051 #
1052 #If qid/date.html exists just return.
1053 #Else create qid/ if necessary and call make_date
1054 #to make the F<date.html> file.
1055 #
1056 #=cut
1057
1058 sub check_date_file {
1059 my($qid,$qn,$qs) = @_;
1060 # do we have the necessary infrastructure?
1061 if (open (FIRST,'<'.$qid."date.html") ) { # yes
1062 # OK, close it.
1063 close (FIRST);
1064 } else { # no, make dir.
1065 if (mkdir ($qid, 0755) ) {
1066 if ($! =~ m/file exists/i) { # already done
1067 die "Can't create directory $qid.\nReason $!";
1068 }
1069 }
1070 chmod 0755, $qid || die "Can't chmod directory $qid.\nReason $!";
1071 &make_date($qid,$qn,$qs);
1072 }
1073 print STDERR "date exists, " if $main::v_dbg;
1074 }
1075
1076 #=head1 NAME
1077 #
1078 #read_query($prompt) - read a string from STDIN.
1079 #
1080 #=head1 DESCRIPTION
1081 #
1082 #read STDIN, with a prompt and backspace editing, until <return>
1083 #
1084 #=cut
1085
1086 sub read_query {
1087 my($prompt) = @_;
1088 my($query) = '';
1089 my($c) = '';
1090 my($oldfh) = select(STDOUT); $| =1; select ($oldfh);
1091 print $prompt;
1092 while (read(STDIN,$c,1)) { # get a byte.
1093 # printf STDERR "%02x",ord($c);
1094 last if $c eq "\x0a";
1095 if ($c eq "\x08") {
1096 chop ($query);
1097 next;
1098 } else {
1099 $query .= $c;
1100 }
1101 }
1102 # print STDERR "\ni see $query\n";
1103 return ($query);
1104 }
1105
1106 #=head1 NAME
1107 #
1108 #read_query_list($prompt) - read a list from STDIN.
1109 #
1110 #=head1 DESCRIPTION
1111 #
1112 #read STDIN, with a prompt and backspace editing, until <blank-line>
1113 #
1114 #=cut
1115
1116 sub read_query_list {
1117 my($prompt) = @_;
1118 my(@query_list);
1119 my($s);
1120 while (1) {
1121 $s = &read_query($prompt);
1122 last unless ($s);
1123 push(@query_list,$s);
1124 }
1125 # print STDERR "\ni see $query_list\n";
1126 return (@query_list);
1127 }
1128
1129 #=head1 NAME
1130 #
1131 #C<format_link($template,$field,$data)> - create hyper links from a template.
1132 #
1133 #=head1 DESCRIPTION
1134 #
1135 #Replace the $field with $data in the $template given.
1136 #For example:
1137 # print C<&format_link("Hello place.\n","place","world");>
1138 #produces
1139 # Hello world.
1140 #
1141 #Used to replace default strings in the default documents with
1142 #user supplied information.
1143 #
1144 #=cut
1145
1146 # format by text replacement.
1147 sub format_link {
1148 my ($unformated,$field,$data) = @_;
1149 my ($temp) = $unformated; # start with unformated string.
1150 $temp =~ s/$field/$data/; # make the replacement.
1151 return ($temp);
1152 }
1153
1154 #=head1 NAME
1155 #
1156 #C<make_link($template,$url,$title,$description)> - create url.
1157 #
1158 #=head1 DESCRIPTION
1159 #
1160 #Replace the URL, TITLE, and DESCRIPTION with $url, $title, and
1161 #$description (respectively) in the $template given.
1162 #
1163 #Used to convert a url template to a hyper-link with title and description.
1164 #
1165 #=cut
1166
1167 sub make_link {
1168 my ($template,$url,$title,$description) = @_;
1169 my ($link) = $template;
1170 $link =~ s/URL/$url/ if defined($url);
1171 $link =~ s/TITLE/$title/ if defined($title);
1172 $link =~ s/DESCRIPTION/$description/ if defined($description);
1173 return ($link);
1174 }
1175
1176 #=head1 NAME
1177 #
1178 #C<make_no_link($template,$url,$title,$description)> - create url.
1179 #
1180 #=head1 DESCRIPTION
1181 #
1182 #Replace the URL, TITLE, and DESCRIPTION with $url, $title, and
1183 #$description (respectively) in the $template given.
1184 #
1185 #Used to convert a url template to a url with title and description.
1186 #
1187 #=cut
1188
1189 sub make_no_link {
1190 my ($template,$url,$title,$description) = @_;
1191 my ($link) = $template;
1192 $link =~ s/URL/$url/ if defined($url);
1193 $link =~ s/TITLE/$title/ if defined($title);
1194 $link =~ s/DESCRIPTION/$description/ if defined($description);
1195 return ($link);
1196 }
1197
1198 #=head1 NAME
1199 #
1200 #C<get_weekly_parts($qid)> - break input file into sub-fields.
1201 #
1202 #=head1 DESCRIPTION
1203 #
1204 #Used to convert an input file into the data elements, template and headings
1205 #required to build nice looking web pages.
1206 #
1207 #=cut
1208
1209 #
1210 # read top.html to get the basic format of the web pages.
1211 # parts include Top, Topic, Appended, Suspended, Bottom
1212 # sub-parts include Heading, Template, actual contents.
1213 # these objects are identified and extracted from the
1214 # complete file. The format for all derived documents
1215 # is determined by this file. How the objects are combined
1216 # to created dervied pages is determined by the software
1217 # enclosed here-in.
1218 #
1219 sub get_weekly_parts {
1220 my($qid) = @_;
1221 $/ = undef(); # enable paragraph mode.
1222 my($Top,$Bottom);
1223 my($AppendedHeading,$AppendedTemplate,$Appended);
1224 my($SuspendedHeading,$SuspendedTemplate,$Suspended);
1225 open (PARTS,'<'.$qid.'date.html') || die "Can't open first date input file.\nReason: $!\n";
1226 my($part) = <PARTS>;
1227 close (PARTS);
1228 # print STDERR "Part:\"$part\"\n";
1229
1230 $Top = &get_pair_part($part,"Top");
1231
1232 $AppendedHeading = &get_part($part,"AppendedHeading");
1233 $AppendedTemplate = &get_part($part,"AppendedTemplate");
1234 $Appended = &get_pair_part($part,"Appended");
1235
1236 $SuspendedHeading = &get_part($part,"SuspendedHeading");
1237 $SuspendedTemplate = &get_part($part,"SuspendedTemplate");
1238 $Suspended = &get_pair_part($part,"Suspended");
1239
1240 $Bottom = &get_pair_part($part,"Bottom");
1241 return($Top,
1242 $AppendedHeading,$AppendedTemplate,$Appended,
1243 $SuspendedHeading,$SuspendedTemplate,$Suspended,
1244 $Bottom);
1245 }
1246
1247 #=head1 NAME
1248 #
1249 #C<get_summary_parts($qid)> - break input file into sub-fields.
1250 #
1251 #=head1 DESCRIPTION
1252 #
1253 #Used to convert an input file into the data elements, template and headings
1254 #required to build nice looking web pages.
1255 #
1256 #=cut
1257
1258 sub get_summary_parts {
1259 my($qid) = @_;
1260 $/ = undef(); # enable paragraph mode.
1261 my($Top,$Query,$SearchEngine,@QueryOptions,$URLFilter,$Bottom);
1262 my($SummaryHeading,$SummaryTemplate,$Summary);
1263 my($WeeklyHeading,$WeeklyTemplate,$Weekly);
1264 open (PARTS,'<'.$qid.'index.html') || die "Can't open index.html input file.\nReason: $!\n";
1265 my($part) = <PARTS>;
1266 close (PARTS);
1267 # print STDERR "Part:\"$part\"\n";
1268
1269 $Top = &get_pair_part($part,"Top");
1270 $Query = &get_inline_part($part,"Query");
1271 $SearchEngine = &get_inline_part($part,"SearchEngine");
1272 # get array of key=value pairs
1273 @QueryOptions = &get_inline_list($part,"QueryOptions");
1274 $URLFilter = &get_inline_part($part,"URLFilter");
1275
1276 $SummaryHeading = &get_part($part,"SummaryHeading");
1277 $SummaryTemplate = &get_part($part,"SummaryTemplate");
1278 $Summary = &get_pair_part($part,"Summary");
1279
1280 $WeeklyHeading = &get_part($part,"WeeklyHeading");
1281 $WeeklyTemplate = &get_part($part,"WeeklyTemplate");
1282 $Weekly = &get_pair_part($part,"Weekly");
1283
1284 $Bottom = &get_pair_part($part,"Bottom");
1285 return($Top,$Query,$SearchEngine,$URLFilter,
1286 $SummaryHeading,$SummaryTemplate,$Summary,
1287 $WeeklyHeading,$WeeklyTemplate,$Weekly,
1288 $Bottom,@QueryOptions);
1289 }
1290
1291 #=head1 NAME
1292 #
1293 #C<get_pair_part($part,$mark)> - locate and return sub-fields.
1294 #
1295 #=head1 DESCRIPTION
1296 #
1297 #Use regular expressions to locate <!--$mark--> and <!--/$mark--> and
1298 #return everything in between (including <return>s).
1299 #
1300 #=cut
1301
1302 # these objects are surrounded by <!--x--> <!--/x--> comments
1303 # to be easily recognized; but always display..
1304 sub get_pair_part {
1305 my($part,$mark) = @_;
1306 if ($part =~ m,<!--$mark-->\n(.*)<!--/$mark-->,s) {
1307 # print STDERR "$mark: \"$1\"\n";
1308 return ($1);
1309 }
1310 # print STDERR "Warning: can't find <!--$mark--> ... <--/$mark-->\n" if ($v_dbg);
1311 return ("");
1312 }
1313
1314 #=head1 NAME
1315 #
1316 #C<get_part($part,$mark)> - locate and return sub-fields.
1317 #
1318 #=head1 DESCRIPTION
1319 #
1320 #Use regular expressions to locate <!--$mark\n and /$mark--> and
1321 #return everything in between (including <return>s).
1322 #
1323 #=cut
1324
1325 # these objects are surrounded by similiar matching x /x marks.
1326 # these objects are actually comments and won't be seen unless
1327 # modified.
1328 sub get_part {
1329 my($part,$mark) = @_;
1330 if ($part =~ m,<!--$mark\n(.*)/$mark-->,s) {
1331 # print STDERR "$mark: \"$1\"\n";
1332 return ($1);
1333 }
1334 # print STDERR "Warning: can't find <!--$mark\\n ... /$mark-->\n" if ($v_dbg);
1335 return ("");
1336 }
1337
1338 #=head1 NAME
1339 #
1340 #C<get_inline_part($part,$mark)> - locate and return sub-fields.
1341 #
1342 #=head1 DESCRIPTION
1343 #
1344 #Use regular expressions to locate <!--$mark{ and }/$mark--> and
1345 #return everything in between.
1346 #
1347 #=cut
1348
1349 # these objects are surrounded by similiar matching x /x marks.
1350 # these objects are actually comments and won't be seen unless
1351 # modified.
1352 sub get_inline_part {
1353 my($part,$mark) = @_;
1354 if ($part =~ m,<!--$mark\{(.*)\}/$mark-->,s) {
1355 # print STDERR "inline $mark: \{$1\}\n";
1356 return ($1);
1357 }
1358 # print STDERR "Warning: can't find <!--$mark\{ ... \}/$mark-->\n" if ($v_dbg);
1359 return ("");
1360 }
1361
1362
1363 #=head1 NAME
1364 #
1365 #C<get_inline_list($part,$mark)> - locate and return sub-fields.
1366 #
1367 #=head1 DESCRIPTION
1368 #
•1369 #Use regular expressions to locate multiple occurrences of
1370 #<!--$mark{ and }/$mark--> and return them as a list.
1371 #
1372 #=cut
1373
1374 # these objects are surrounded by similiar matching x /x marks.
1375 # these objects are actually comments and won't be seen unless
1376 # modified.
1377 sub get_inline_list {
1378 my($part,$mark) = @_;
1379 if ($part =~ m,<!--$mark\{(.*)\}/$mark-->,s) {
1380 my(@PARTS) = split(/\n/, $part);
1381 my(@LINES) = grep(m,<!--$mark\{(.*)\}/$mark-->,s, @PARTS);
1382 my(@LIST,$is);
1383 foreach (@LINES) {
1384 next unless ($_ =~ m,<!--$mark\{(.*)\}/$mark-->,s);
1385 # print STDERR "inline $mark: \{$1\}\n";
1386 push (@LIST,$1);
1387 }
1388 return (@LIST);
1389 }
1390 # print STDERR "Warning: can't find <!--$mark\{ ... \}/$mark-->\n" if ($v_dbg);
1391 return ("");
1392 }
1393
1394 #=head1 NAME
1395 #
1396 #C<make_index($qid)> - make working copy of F<index.html>.
1397 #
1398 #=head1 DESCRIPTION
1399 #
1400 #Create F<qid/index.html> from either F<first_index.html>
1401 #or from 'memory'.
1402 #
1403 #=cut
1404
1405 # check the root directory for default first_index file;
1406 # else make one of our own.
1407 sub make_index {
1408 my ($qid) = @_;
1409 open (INDEX, ">$qid/index.html") || die "Can't create index.html in $qid\nReason $!";
1410 # copy user-provided file...
1411 if (open (DEFAULT, "<$qid/../first_index.html") ) { # look for a default
1412 # copy in default provided by user.
1413 while (<DEFAULT>) {
1414 print INDEX $_;
1415 }
1416 close (DEFAULT) || die "Can't close file $qid/../first_index.html: $!";
1417 close (INDEX) || die "Can't close file $qid/index.html: $!";
1418 return;
1419 }
1420 # or OUR provided file
1421 my($it) = <<EOF;
1422 <HEAD>
1423 <Title> index.html empty page to establish summary file format </Title>
1424 </HEAD>
1425
1426 <BODY>
1427 <!--Top-->
1428 <!--Place the html to make your page start to look nice here-->
1429 <!--In the next line place the pretty name of the query.-->
1430 <h1>AutoSearch WEB Searching</h1>
1431 <!--/Top-->
1432
1433 <!--In the next line place the actual query.-->
1434 <!--Query{ask user}/Query-->
1435 <!--In the next line place the actual search engine.-->
1436 <!--SearchEngine{Null}/SearchEngine-->
1437 <!--In the next line(s) place the query/search engine specific options.-->
1438 <!--QueryOptions{}/QueryOptions-->
1439 <!--In the next line place the actual url filter.-->
1440 <!--URLFilter{}/URLFilter-->
1441
1442 <!--SummaryHeading
1443 <h3>Summary of WEB search results</h3><p>
1444 /SummaryHeading-->
1445
1446 <!--The list of unique 'hits' including a url and title.-->
1447 <!--SummaryTemplate
1448 <a href="URL">TITLE</a><br>
1449 /SummaryTemplate-->
1450
1451 <!--Summary-->
1452 <!--the list of unique 'hits' goes here.-->
1453 <!--/Summary-->
1454
1455 <!--WeeklyHeading
1456 <hr>
1457 <h3>Weekly Search Results</h3><p>
1458 /WeeklyHeading-->
1459
1460 <!--The list of 'hits' including a url and title.-->
1461 <!--WeeklyTemplate
1462 <a href="URL">TITLE</a><br>
1463 /WeeklyTemplate-->
1464
1465 <!--Weekly-->
1466 <!--the list of weekly results goes here.-->
1467 <!--/Weekly-->
1468
1469 <!--Bottom-->
1470 <!--Place the html to make your page finish up sharply here-->
1471 <p>
1472 Last modified October 17, 1996.
1473 <!--/Bottom-->
1474 </BODY>
1475 EOF
1476
1477 print INDEX $it;
1478 close(INDEX);
1479 }
1480
1481 #=head1 NAME
1482 #
1483 #make_date($qid) - make working copy of F<date.html>.
1484 #
1485 #=head1 DESCRIPTION
1486 #
1487 #Create F<qid/date.html> from either F<first_date.html>
1488 #or from 'memory'.
1489 #
1490 #=cut
1491
1492 # check the root directory for default first_date file;
1493 # else make one of our own.
1494 sub make_date {
1495 my($qid,$qn,$qs) = @_;
1496 open (FIRST,'>'.$qid."date.html") || die "Can't create date in $qid\nReason $!";
1497 # copy user-provided file...
1498 if (open (DEFAULT,'<'.$qid."../first_date.html") ) { # look for a default
1499 # copy in default provided by user.
1500 while (<DEFAULT>) {
1501 s/{ask user}/\{$qs\}/ if (m,Query\{ask user\}/Query,);
1502 s/AutoSearch WEB Searching/$qn/ if (m,AutoSearch WEB Searching,);
1503 print FIRST $_;
1504 }
1505 close (DEFAULT) || die "Can't close default first_date.html file.\nReason:$!";
1506 close (FIRST) || die "Can't close date.html file.\nReason:$!";
1507 return;
1508 }
1509 # or OUR provided file
1510 my($it) = <<EOF;
1511 <HEAD>
1512 <Title> first_date.html empty page to establish weekly file format </Title>
1513 </HEAD>
1514
1515 <BODY>
1516 <!--Top-->
1517 <!--Place the html to make your page start to look nice here-->
1518 <!--In the next line place the pretty name of the query.-->
1519 <h1>AutoSearch WEB Searching</h1>
1520 <!--/Top-->
1521
1522 <!--The Title of the search results. 'DATE' will be replaced with the date.-->
1523 <!--AppendedHeading
1524 <h3>Web Search Results for DATE</h3><p>
1525 /AppendedHeading-->
1526
1527 <!--The list of 'hits' including a url, title and description.-->
1528 <!--AppendedTemplate
1529 <a href="URL">TITLE</a><br>
1530 DESCRIPTION
1531 /AppendedTemplate-->
1532
1533 <!--Appended-->
1534 <!--the list of 'hits' goes here.-->
1535 <!--/Appended-->
1536
1537 <!--SuspendedHeading
1538 <hr>
1539 <h3>URLs Apparently Suspended</h3><p>
1540 /SuspendedHeading-->
1541
1542 <!--The list of 'misses' only the title.-->
1543 <!--SuspendedTemplate
1544 TITLE<br>
1545 /SuspendedTemplate-->
1546
1547 <!--Suspended-->
1548 <!--the list of 'misses' goes here.-->
1549 <!--/Suspended-->
1550
1551 <!--Bottom-->
1552 <!--Place the html to make your page finish up sharply here-->
1553 <p>
1554 Web searches maintained by <a href="http://www.isi.edu/lsam/tools/autosearch">AutoSearch</a>.
1555 <!--/Bottom-->
1556 </BODY>
1557 EOF
1558 $it =~ s/{ask user}/\{$qs\}/ if ($it =~ m,Query\{ask user\}/Query,);
1559 $it =~ s/AutoSearch WEB Searching/$qn/ if ($it =~ m,AutoSearch WEB Searching,);
1560 print FIRST $it;
1561 close(FIRST);
1562 }
1563
1564 sub time_now {
1565 return strftime("%m/%d/%Y %H:%M:%S", localtime(time));
1566 }
1567
1568 sub time_today {
1569 return strftime("%b %d, %Y", localtime(time));
1570 }
1571
1572 sub time_file_of_the_day_numeric {
1573 return strftime("%Y%m%d", localtime(time));
1574 }
1575
1576
1577 sub http_error_as_nice_string {
1578 my($response) = @_;
1579 my($message) = $response->message();
1580 my($code) = $response->code();
1581 chomp($message);
1582 return "$message (code $code)";
1583 }
1584
1585 sub add_to_hash
1586 {
1587 # This is a bit of a hack. A set of CGI options is not strictly a
1588 # hash, because multiple values for the same key can be specified.
1589 # To get around this, we rely on the fact that this hash of options
1590 # is only used to construct a CGI parameter list. If we see
1591 # multiple values for the same key, we append the multiple values
1592 # onto the value of the key in CGI '?key=value' format.
1593 my ($key, $value, $hashref) = @_;
1594 if (exists($hashref->{$key}) && $hashref->{$key} ne '')
1595 {
1596 # There was already an option of this key given; append
1597 # multiple values as CGI arguments:
1598 $hashref->{$key} .= "&$key=$value";
1599 } # if exists
1600 else
1601 {
1602 # This is the only instance of this key; just insert the
1603 # hash value:
1604 $hashref->{$key} = $value;
1605 }
1606 } # add_to_hash
1607
1608 =head1 DESCRIPTION
1609
1610 B<AutoSearch> performs a web-based search and puts the results
1611 set in F<qid/index.html>.
1612 Subsequent searches (i.e., the second form above)
•1613 B<AutoSearch> determine what changes (if any) occurred to the
1614 results sent since the last run.
1615 These incremental changes are recorded in F<qid/YYYYMMDD.html>.
1616
1617 B<AutoSearch> is amenable to be run as a B<cron> job because all
1618 the input parameters are saved in the web pages. B<AutoSearch>
1619 can act as a automated query agent for a particular search. The output
1620 files are designed to be a set of web pages to easily display the
1621 results set with a web browser.
1622
1623 Example:
1624
1625 AutoSearch -n 'LSAM Replication'
1626 -s '"lsam replication"'
1627 -e AltaVista
1628 replication_query
1629
1630 This query (which should be all on one line)
1631 creates a directory replication_query
1632 and fills it with the fascinating output of the AltaVista query
1633 on C<"lsam replication">,
1634 with pages titled ``LSAM Replication''.
1635 (Note the quoting: the single quotes in
1636 C<'"lsam replication"'> are for the shell,
1637 the double quotes are for AltaVista
1638 to search for the phrase rather than the separate words.)
1639
1640 A more complicated example:
1641
1642 AutoSearch -n 'External Links to LSAM'
1643 -s '(link:www.isi.edu/lsam or link:www.isi.edu/~lsam) -url:isi.edu'
1644 -e AltaVista::AdvancedWeb
1645 -o coolness=hot
1646
1647 This query does an advanced AltaVista search
1648 and specifies the (hypothetical) ``coolness'' option
1649 to the search engine.
1650
1651 =head1 OPTIONS
1652
1653 =over
1654
1655 =item C<qid>
1656
1657 The I<query identifer> specifies the directory in which all the
1658 files that relate to this query and search results will live.
1659 It can be an absolute path, or a relative path from cwd.
1660 If the directory does not exist, it will be created and a new search started.
1661
1662 =item C<--stats>
1663
1664 Show search statistics: the query string,
1665 number of hits, number of filtered hits,
1666 filter string, number of suspended (deleted) hits,
1667 previous set size, current set size, etc.
1668
1669 =item C<-v> or C<--verbose>
1670
1671 Verbose: output additional messages and warnings.
1672
1673 =item C<-n> or C<--qn> or C<--queryname>
1674
1675 Specify the query name. The query name is used as a heading in the
1676 web pages, therefore it should be a 'nice' looking version of the
1677 query string.
1678
1679 =item C<-s> or C<--qs> or C<--querystring>
1680
1681 Specify the query string. The query string is the character string
1682 which will be submitted to the search engine. You may include special
1683 characters to group or to qualify the search.
1684
1685 =item C<-e> or C<--engine>
1686
1687 Specify the search engine. The query string will be submitted
1688 to the user specified search engine.
1689
1690 In many cases there are specialized versions of search engines.
1691 For example, B<AltaVista::AdvancedWeb> and B<AltaVista::News>
1692 allow more powerful and Usenet searches.
1693 See L<AltaVista> or the man page for your search engine
1694 for details about specialized variations.
1695
1696 =item C<--listnewurls>
1697
1698 In addition to all the normal file maintenance,
1699 print all new URLs to STDOUT, one per line.
1700
1701 =item C<-o> or C<--options>
1702
1703 Specify the query options. The query options will be submitted
1704 to the user search engine with the query string. This feature
1705 permits modification of the query string for a specific search
1706 engine or option. More than one query option may be specified.
1707
1708 Example:
1709 C<-o what=news>
1710 causes AltaVista to search Usenet.
1711 Although this works, the preferred mechanism
1712 in this case would be C<-e AltaVista::News> or C<-e AltaVista::AdvancedNews>.
1713 Options are intended for internal or expert use.
1714
1715
1716 =item C<-f> or C<--uf> or C<--urlfilter>
1717
1718 This option specifies a regular expression which will
1719 be compared against the URLs of any results;
1720 if they match the case-insensitive regular expression, they will be removed
1721 from the hit set.
1722
1723 Example:
1724 C<-f '.*\.isi\.edu'> avoids all of ISI's web pages.
1725
1726 =item C<--cleanup i>
1727
1728 Delete all traces of query results from more than i days ago. If
1729 --cleanup is given, all other options other than the qid will be
1730 ignored.
1731
1732 =item C<--cmdline>
1733
1734 Reconstruct the complete command line (AutoSearch and all its
1735 arguments) that was used to create the query results. Command line
1736 will be shown on STDERR. If --cmdline is given, all other options
1737 other than the qid will be ignored.
1738
1739 =item C<--mail user@address> or C<-m user@address>
1740
1741 After search is complete, send email to that user, listing the NEW results.
1742 Email is HTML format.
1743 Requires the Email::Send and related modules.
1744 If you send email through an SMTP server, you must set environment variable SMTPSERVER to your server name or IP address.
1745 If your SMTP server requires password, you must set environment variables SMTPUSERNAME and SMTPPASSWORD.
1746 If you send email via sendmail, you should set environment variable SENDMAIL if the sendmail executable is not in the path.
1747
1748 =item C<--emailfrom user@address>
1749
1750 If your outgoing mail server rejects email from certain users,
1751 you can use this argument to set the From: header.
1752
1753 =item C<--userid bbunny>
1754
1755 If the search engine requires a login/password (e.g. Ebay::Completed), use this.
1756
1757 =item C<--password Carr0t5>
1758
1759 If the search engine requires a login/password (e.g. Ebay::Mature), use this.
1760
1761 =back
1762
1763
1764 =head1 DESCRIPTION
1765
1766 B<AutoSearch> submits a query to a search engine, produces HTML pages
1767 that reflect the set of 'hits' (filtered search results) returned by
1768 the search engine, and tracks these results over time. The URL and
1769 title are displayed in the F<qid/index.html>, the URL, the title, and
1770 description are displayed in the 'weekly' files.
1771
1772 To organize these results, each search result is placed in a query
1773 information directory (qid). The directory becomes the search results
1774 'handle', an easy way to track a set of results. Thus a qid of
1775 C</usr/local/htdocs/lsam/autosearch/load_balancing> might locate the
1776 results on your web server at
1777 C<http://www.isi.edu/lsam/autosearch/load_balancing>.
1778
1779 Inside the qid directory you will find files relating to this query.
1780 The primary file is F<index.html>, which reflects the latest search
1781 results. Every not-filtered hit for every search is stored in
1782 F<index.html>. When a hit is no longer found by the search engine it
1783 a removed from F<index.html>. As new results for a search are
1784 returned from the search engine they are placed in F<index.html>.
1785
1786 At the bottom of F<index.html>, there is a heading "Weekly Search
1787 Results", which is updated each time the search is submitted (see
1788 L<AUTOMATED SEARCHING>). The list of search runs is stored in reverse
1789 chronological order. Runs which provide no new information are
1790 identified with
1791
1792 No Unique Results found for search on <date>
1793
1794 Runs which contain changes are identified by
1795
1796 Web search results for search on <date>
1797
1798 which will be linked a page detailing the changes from that run.
1799
1800 Detailed search results are noted in weekly files. These files are
1801 named F<YYYYMMDD.html> and are stored in the qid directory. The
1802 weekly files include THE URL, title, and a the description (if
1803 available). The title is a link to the original web page.
1804
1805
1806 =head1 AUTOMATED SEARCHING
1807
1808 On UNIX-like systems, cron(1) may be used to establish periodic
1809 searches and the web pages will be maintained by B<AutoSearch>. To
1810 establish the first search, use the first example under SYNOPSIS. You
1811 must specify the qid, query name and query string. If any of the
1812 items are missing, you will be interactively prompted for the missing
1813 item(s).
1814
1815 Once the first search is complete you can re-run the search with the
1816 second form under SYNOPSIS.
1817
1818 A cron entry like:
1819
1820 0 3 * * 1 /nfs/u1/wls/AutoSearch.pl /www/div7/lsam/autosearch/caching
1821
1822 might be used to run the search each Monday at 3:00 AM. The query
1823 name and query string may be repeated; but they will not be used.
1824 This means that with a cron line like:
1825
1826 0 3 * * 1 /nfs/u1/wls/AutoSearch.pl /www/div7/lsam/autosearch/caching -n caching -s caching
1827
1828 a whole new search series can be originated by
1829
1830 rm -r /www/div7/lsam/autosearch/caching
1831
1832 However, the only reason to start a new search series would be to
1833 throw away the old weekly files.
1834
1835 We don't recommend running searches more than once per day, but if so
1836 the per-run files will be updated in-place. Any changes are added to
1837 the page with a comment that "Recently Added:"; and deletions are
1838 indicated with "Recently Suspended:."
1839
1840 =head1 CHANGING THE LOOK OF THE PAGES
1841
1842 The basic format of these two pages is simple and customizable. One
1843 requirement is that the basic structure remain unchanged. HTML
1844 comments are used to identify sections of the document. Almost
1845 everything can be changed except for the strings which identify the
1846 section starts and ends.
1847
1848 Noteworthy tags and their meaning:
1849
1850 =over 16
1851
1852 =item <!--Top-->.*<!--/Top-->
1853
1854 The text contained within this tag is placed at the top of the output
1855 page. If the text contains I<AutoSearch WEB Searching>, then the
1856 query name will replace it. If the text does not contain this magic
1857 string and it is the first ever search, the user will be asked for a
1858 query name.
1859
1860 =item <!--Query{.*}/Query-->
1861
1862 The text contained between the braces is the query string. This is
1863 how B<AutoSearch> maintains the query string. You may edit this
1864 string to change the query string; but only in F<qid/index.html>. The
1865 text I<ask user> is special and will force B<AutoSearch> to request
1866 the search string from the user.
1867
1868 =item <!--SearchEngine{.*}/SearchEngine-->
1869
1870 The text contained between the braces is the search engine. Other
1871 engines supported are HotBot and Lycos. You may edit this string to
1872 change the engine used; but only in F<qid/index.html>. The text I<ask
1873 user> is special and will force B<AutoSearch> to to request the search
1874 string from the user.
1875
1876 =item <!--QueryOptions{.*}/QueryOptions-->
1877
1878 The text contained between the braces specifies a query options.
•1879 Multiple occurrences of this command are allowed to specify multiple
1880 options.
1881
1882 =item <!--URLFilter{.*}/URLFilter-->
1883
1884 The text contained between the braces is the URL filter. This is how
1885 B<AutoSearch> maintains the filter. Again you may edit this string to
1886 change the query string; but only in F<qid/index.html>. The text
1887 I<ask user> is special and will force B<AutoSearch> to ask the user
1888 (STDIN) for the query string. When setting up the first search, you
1889 must edit F<first_index.html>, not F<qid/index.html>. The URL filter
1890 is a standard perl5 regular expression. URLs which do not match will
1891 be kept.
1892
1893 =item <!--Bottom-->.*<!--/Bottom-->
1894
1895 The text contained within this tag is placed at the bottom of the
1896 output page. This is a good place to put navigation, page owner
1897 information, etc.
1898
1899 =back
1900
1901 The remainder of the tags fall into a triplet of I<~Heading>,
1902 I<~Template>, and I<~>, where ~ is Summary, Weekly, Appended, and
1903 Suspended. The sub-sections appear in the order given. To produce a
1904 section B<AutoSearch> outputs the heading, the template, the section,
1905 n copies of the formatted data, and an /section. The tags and their
1906 function are:
1907
1908 =over 16
1909
1910 =item ~Heading
1911
1912 The heading tag identifies the heading for a section of the output
1913 file. The SummaryHeading is for the summary portion, etc. The
1914 section may be empty (e.g., Suspended) and thus no heading is output.
1915
1916 =item ~Template
1917
1918 The template tag identifies how each item is to be formatted. Simple
1919 text replacement is used to change the template into the actual output
1920 text. The text to be replaced is noted in ALLCAPS.
1921
1922 =item ~
1923
1924 This tag is used to locate the section (Summary, Weekly, etc.). This
1925 section represents the actual n-items of data.
1926
1927 =back
1928
1929 You can edit these values in the F<qid/index.html> page of an existing
1930 search. The file F<first_index.html> (in the directory above F<qid>)
1931 will be used as a default template for new queries.
1932
1933 Examples of these files can be seen in the pages under
1934 C<http://www.isi.edu/lsam/tools/autosearch/>, or in the output generated by
1935 a new AutoSearch.
1936
1937 =head1 FILES
1938
1939 =over 20
1940
1941 =item F<first_index.html>
1942
1943 optional file to determine the default format of the F<index.html>
1944 file of a new query.
1945
1946 =item F<first_date.html>
1947
1948 optional file to determine the default format of the F<YYYYMMDD.html>
1949 file for a new query.
1950
1951 =item F<qid/index.html>
1952
1953 (automatically created) latest search results, and reverse
1954 chronological list of periodic searches.
1955
1956 =item F<qid/date.html>
1957
1958 file used as a template for the F<YYYYMMDD.html> files.
1959
1960 =item F<qid/YYYYMMDD.html>
1961
1962 (automatically created) summary of changes for a particular date (AKA
1963 'Weekly' file).
1964
1965 =back
1966
1967 Optional files F<first_index.html> and F<first_date.html> are used for
1968 the initial search as a template for F<qid/index.html> and
1969 F<date.html>, respectively. If either of these files does not exist;
1970 a default-default template is stored within the F<AutoSearch> source.
1971 The intention of these two files is to permit a user to establish a
1972 framework for a group of search sets which have a common format. By
1973 leaving the default query name and query string alone, they will be
1974 overridden by command line inputs.
1975
1976 =head1 SEE ALSO
1977
1978 For the library, see L<WWW::Search>,
1979 for the perl regular expressions, see L<perlre>.
1980
1981 =head1 AUTHORS
1982
1983 Wm. L. Scheding
1984
1985 B<AutoSearch> is a re-implementation of an earlier version written by
1986 Kedar Jog.
1987
1988 =head1 COPYRIGHT
1989
1990 Copyright (C) 1996-1997 University of Southern California.
1991 All rights reserved.
1992
1993 Redistribution and use in source and binary forms are permitted
1994 provided that the above copyright notice and this paragraph are
1995 duplicated in all such forms and that any documentation, advertising
1996 materials, and other materials related to such distribution and use
1997 acknowledge that the software was developed by the University of
1998 Southern California, Information Sciences Institute. The name of the
1999 University may not be used to endorse or promote products derived from
2000 this software without specific prior written permission.
2001
2002 THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
2003 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
2004 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2005
2006 =head1 DESIRED FEATURES
2007
2008 These are good ideas that people have suggested.
2009
2010 =over 4
2011
2012 =item URL validation.
2013
2014 Validate the status of each URL (with HTTP HEAD requests) and indicate
2015 this status in the output.
2016
2017 =item Multi-search.
2018
2019 It should be possible to merge the results of searches from two
2020 search-engines. If this merger were done as a new search engine, this
2021 operation would be transparent to AutoSearch.
2022
2023 =back
2024
2025 =head1 BUGS
2026
2027 None known at this time; please inform the maintainer [email protected]
2028 if any crop up.
2029
2030 =cut
2031
2032 __END__
2033