Here is the site_of_the_day.pl file that you will have to run every night with crontab.
#################################################################
# Set up Variables
#################################################################
$txtfile = '/opt/guide/HTML/txt/generated/siteoftheday.txt';
#################################################################
# Main Script
#################################################################
# Required Librariers
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \
require "admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}
# ========================================================
eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.
sub main {
# --------------------------------------------------------
my ($id, $delim, $time);
my ($count, $rand, $find);
$delim = quotemeta($db_delim);
$time = time();
# Pull out the total number of links.
open (COUNT, "<$db_hits_path/index.count") or &error ("unable to open index count file: $db_hits_path/index.count. Reason: $!");
$count = int <COUNT>;
close COUNT;
# Get the random line from the url lookup database.
srand;
$find = 0; $rand = int (rand ($count + 0.5)); ($rand == $count) and ($rand--);
open (URL, "<$db_url_name") or &error ("unable to open url database: $db_url_name. Reason: $!");
while (<URL> ) {
$find++ == $rand or next;
/(.+)$delim/o or next;
$id = $1;
last;
}
close URL;
$id or &error ("Can't find random line: $rand.");
if ($id =~ /^\d+$/) {
my (%rec) = &get_record ($id);
($rec{$db_key} eq $id) ?
&build_page :
&error ("Random ID $id is not a valid ID.");
} else {
&error ("Can't find random Links ID: $id.");
}
}
sub build_page {
# --------------------------------------------------------
open (PAGE, ">$txtfile") or &error ("unable to open textfile: $txtfile. Reason: $!");
print PAGE &site_html_site_of_the_day (%rec);
close PAGE;
}
sub error {
# ------------------------------------------
#
print "Content-type: text/plain\n\n";
print "Error: $_[0]\n";
exit;
}
And here is the modification for site_html.pl
# --------------------------------------------------------
# This routine determines how the sotd page will look like.
#
my %rec = @_;
$output = qq~
PUT YOUR HTML HERE!
(you can use $rec{ ***** })
~;
return $output;
}
[This message has been edited by chrishintz (edited June 27, 1999).]
Code:
#!/usr/bin/perl #################################################################
# Set up Variables
#################################################################
$txtfile = '/opt/guide/HTML/txt/generated/siteoftheday.txt';
#################################################################
# Main Script
#################################################################
# Required Librariers
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \
require "admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}
# ========================================================
eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.
sub main {
# --------------------------------------------------------
my ($id, $delim, $time);
my ($count, $rand, $find);
$delim = quotemeta($db_delim);
$time = time();
# Pull out the total number of links.
open (COUNT, "<$db_hits_path/index.count") or &error ("unable to open index count file: $db_hits_path/index.count. Reason: $!");
$count = int <COUNT>;
close COUNT;
# Get the random line from the url lookup database.
srand;
$find = 0; $rand = int (rand ($count + 0.5)); ($rand == $count) and ($rand--);
open (URL, "<$db_url_name") or &error ("unable to open url database: $db_url_name. Reason: $!");
while (<URL> ) {
$find++ == $rand or next;
/(.+)$delim/o or next;
$id = $1;
last;
}
close URL;
$id or &error ("Can't find random line: $rand.");
if ($id =~ /^\d+$/) {
my (%rec) = &get_record ($id);
($rec{$db_key} eq $id) ?
&build_page :
&error ("Random ID $id is not a valid ID.");
} else {
&error ("Can't find random Links ID: $id.");
}
}
sub build_page {
# --------------------------------------------------------
open (PAGE, ">$txtfile") or &error ("unable to open textfile: $txtfile. Reason: $!");
print PAGE &site_html_site_of_the_day (%rec);
close PAGE;
}
sub error {
# ------------------------------------------
#
print "Content-type: text/plain\n\n";
print "Error: $_[0]\n";
exit;
}
And here is the modification for site_html.pl
Code:
sub site_html_site_of_the_day { # --------------------------------------------------------
# This routine determines how the sotd page will look like.
#
my %rec = @_;
$output = qq~
PUT YOUR HTML HERE!
(you can use $rec{ ***** })
~;
return $output;
}
[This message has been edited by chrishintz (edited June 27, 1999).]