X-Git-Url: https://code.th-h.de/?p=usenet%2Fnewsstats.git;a=blobdiff_plain;f=gatherstats.pl;h=e9ae0f8268af50f20d98aa3a4976dce67c57b717;hp=14cd88300441306ea825b8b80251494f179f59b5;hb=fe46be2168065d5bbbebb04e9350cc7fcd5cbeeb;hpb=89db2f904dc9ddd07bfce9c3fe1fe81b58c1aa8b diff --git a/gatherstats.pl b/gatherstats.pl index 14cd883..e9ae0f8 100755 --- a/gatherstats.pl +++ b/gatherstats.pl @@ -54,6 +54,27 @@ die "$MySelf: E: Unknown type '-t $Options{'t'}'!\n" if !exists($LegalTypes{$Opt ### get time period (-m or -p) my ($StartMonth,$EndMonth) = &GetTimePeriod($Options{'m'},$Options{'p'}); +### reformat $Conf{'TLH'} +my $TLH; +if ($Conf{'TLH'}) { + # $Conf{'TLH'} is parsed as an array by Config::Auto; + # make a flat list again, separated by : + if (ref($TLH) eq 'ARRAY') { + $TLH = join(':',@{$Conf{'TLH'}}); + } else { + $TLH = $Conf{'TLH'}; + } + # strip whitespace + $TLH =~ s/\s//g; + # check for illegal characters + die "$MySelf: E: Config error - illegal characters in TLH definition\n" if ($TLH !~ /^[a-zA-Z0-9:]+$/); + if ($TLH =~ /:/) { + # reformat $TLH form a:b to (a)|(b) + $TLH =~ s/:/)|(/g; + $TLH = '(' . $TLH . ')'; + }; +}; + ### read newsgroups list from -l my %ValidGroups = %{&ReadGroupList($Options{'l'})} if $Options{'l'}; @@ -77,7 +98,7 @@ foreach my $Month (&ListMonth($StartMonth,$EndMonth)) { my %Postings; while (($_) = $DBQuery->fetchrow_array) { # get list oft newsgroups and hierarchies from Newsgroups: - my %Newsgroups = ListNewsgroups($_,$Conf{'TLH'},$Options{'l'} ? \%ValidGroups : ''); + my %Newsgroups = ListNewsgroups($_,$TLH,$Options{'l'} ? \%ValidGroups : ''); # count each newsgroup and hierarchy once foreach (sort keys %Newsgroups) { $Postings{$_}++; @@ -94,12 +115,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; };