Gossamer Forum
Home : Products : Links 2.0 : Customization :

help with build_update_newpop

Quote Reply
help with build_update_newpop
I'm having a couple of problems. I created a modified version of jump.cgi because I want to create some statistics around banner impressions on my site. My banner.cgi uses the same method as jump.cgi to log data.

I've added the following code to build_update_newpop in nph-build.cgi to take the info from my data/banners directory and add it to links.db.

my ($id, %hits, @values, $days, @popular, $cutoff);

# Let's collect how many banner impressions we've gotten.
opendir (HITS, $db_banners_path) or &cgierr ("unable to open banners directory: $db_banners_path. Reason: $!");
while (defined ($id = readdir HITS)) {
next unless ($id =~ /^\d+$/);
open (HIT, "$db_banners_path/$id") or &cgierr ("unable to open banner counter: $db_banners_path/$id. Reason: $!");
$hits{$id} = int <HIT>;
close HIT;
}
closedir HITS;

# Now go through the links database and add the banners
open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@values = &split_decode($_);
$values[$db_modified] or print "Warning: No date for line: $_. Skipping..\n" and next LINE;

# Store the new number of banners.
exists $hits{$id} and ($values[$db_banners] = $values[$db_banners] + $hits{$id});

# Finally, clean out the banners directory.
foreach (keys %hits) {
next unless /^\d+$/;
unlink ("$db_banners_path/$_") or &cgierr ("Can't remove banner file: '$db_banners_path/$_'. Reason: $!");
}
}

There are two problems. It's saying it can't remove banner file (in this case, 54) because the file does not exisit. Regardless of whether this file exisits or not, the script thinks it doesn't. Secondly, no data is actually added to links.db even though this should take place before any attempt at unlinking files is made. Any insight?

I appreciate the help!

Ryan

Subject Author Views Date
Thread help with build_update_newpop allthingsfree 790 Nov 5, 2000, 11:10 AM
Post Re: help with build_update_newpop
Stealth 749 Nov 5, 2000, 7:48 PM