X-Git-Url: https://code.th-h.de/?p=usenet%2Fnewsstats.git;a=blobdiff_plain;f=gatherstats.pl;h=886faaeb557347c1bd7ed943d081bb9dc251ae56;hp=a721b3ee927e1483c4126446212288e96748fe83;hb=d3b6810d3d09c7a1dffaef75731624fd9712d914;hpb=ad6097927113a27587ed8b1785f18c4b18db58e8 diff --git a/gatherstats.pl b/gatherstats.pl index a721b3e..886faae 100755 --- a/gatherstats.pl +++ b/gatherstats.pl @@ -77,7 +77,7 @@ foreach my $Month (&ListMonth($StartMonth,$EndMonth)) { my %Postings; while (($_) = $DBQuery->fetchrow_array) { # get list oft newsgroups and hierarchies from Newsgroups: - my %Newsgroups = ListNewsgroups($_,$Options{'l'} ? \%ValidGroups : ''); + my %Newsgroups = ListNewsgroups($_,$Conf{'TLH'},$Options{'l'} ? \%ValidGroups : ''); # count each newsgroup and hierarchy once foreach (sort keys %Newsgroups) { $Postings{$_}++; @@ -94,12 +94,19 @@ foreach my $Month (&ListMonth($StartMonth,$EndMonth)) { }; }; + # delete old data for that month + if (!$Options{'o'}) { + $DBQuery = $DBHandle->do(sprintf("DELETE FROM %s.%s WHERE month = ?",$Conf{'DBDatabase'},$Conf{'DBTableGrps'}),undef,$Month) + or warn sprintf("$MySelf: E: Can't delete old groups data for %s from %s.%s: $DBI::errstr\n",$Month,$Conf{'DBDatabase'},$Conf{'DBTableGrps'}); + }; + print "----- GroupStats -----\n" if $Options{'d'}; foreach my $Newsgroup (sort keys %Postings) { print "$Newsgroup => $Postings{$Newsgroup}\n" if $Options{'d'}; if (!$Options{'o'}) { # write to database - $DBQuery = $DBHandle->prepare(sprintf("REPLACE INTO %s.%s (month,newsgroup,postings) VALUES (?, ?, ?)",$Conf{'DBDatabase'},$Conf{'DBTableGrps'})); + $DBQuery = $DBHandle->prepare(sprintf("INSERT INTO %s.%s (month,newsgroup,postings) VALUES (?, ?, ?)",$Conf{'DBDatabase'},$Conf{'DBTableGrps'})); + # $DBQuery = $DBHandle->prepare(sprintf("REPLACE INTO %s.%s (month,newsgroup,postings) VALUES (?, ?, ?)",$Conf{'DBDatabase'},$Conf{'DBTableGrps'})); $DBQuery->execute($Month, $Newsgroup, $Postings{$Newsgroup}) or die sprintf("$MySelf: E: Can't write groups data for %s/%s to %s.%s: $DBI::errstr\n",$Month,$Newsgroup,$Conf{'DBDatabase'},$Conf{'DBTableGrps'}); $DBQuery->finish; };