Merge branch 'thh-parsedb' into pu
[usenet/newsstats.git] / bin / gatherstats.pl
old mode 100755 (executable)
new mode 100644 (file)
index f545456..b09b73f
@@ -3,17 +3,17 @@
 # gatherstats.pl
 #
 # This script will gather statistical information from a database
-# containing headers and other information from a INN feed.
-# 
+# containing headers and other information from an INN feed.
+#
 # It is part of the NewsStats package.
 #
 # Copyright (c) 2010-2013 Thomas Hochstein <thh@inter.net>
 #
-# It can be redistributed and/or modified under the same terms under 
+# It can be redistributed and/or modified under the same terms under
 # which Perl itself is published.
 
 BEGIN {
-  our $VERSION = "0.01";
+  our $VERSION = "0.02";
   use File::Basename;
   # we're in .../bin, so our module is in ../lib
   push(@INC, dirname($0).'/../lib');
@@ -38,7 +38,7 @@ my %LegalStats;
 
 ### read commandline options
 my ($OptCheckgroupsFile,$OptClientsDB,$OptDebug,$OptGroupsDB,$OptTLH,
-    $OptHostsDB,$OptMonth,$OptRawDB,$OptStatsType,$OptTest);
+    $OptHostsDB,$OptMonth,$OptParseDB,$OptStatsType,$OptTest,$OptConfFile);
 GetOptions ('c|checkgroups=s' => \$OptCheckgroupsFile,
             'clientsdb=s'     => \$OptClientsDB,
             'd|debug!'        => \$OptDebug,
@@ -46,18 +46,19 @@ GetOptions ('c|checkgroups=s' => \$OptCheckgroupsFile,
             'hierarchy=s'     => \$OptTLH,
             'hostsdb=s'       => \$OptHostsDB,
             'm|month=s'       => \$OptMonth,
-            'rawdb=s'         => \$OptRawDB,
+            'parsedb=s'       => \$OptParseDB,
             's|stats=s'       => \$OptStatsType,
             't|test!'         => \$OptTest,
+            'conffile=s'      => \$OptConfFile,
             'h|help'          => \&ShowPOD,
             'V|version'       => \&ShowVersion) or exit 1;
 
 ### read configuration
-my %Conf = %{ReadConfig('')};
+my %Conf = %{ReadConfig($OptConfFile)};
 
 ### override configuration via commandline options
 my %ConfOverride;
-$ConfOverride{'DBTableRaw'}   = $OptRawDB if $OptRawDB;
+$ConfOverride{'DBTableParse'} = $OptParseDB if $OptParseDB;
 $ConfOverride{'DBTableGrps'}  = $OptGroupsDB if $OptGroupsDB;
 $ConfOverride{'DBTableClnts'} = $OptClientsDB if $OptClientsDB;
 $ConfOverride{'DBTableHosts'} = $OptHostsDB if $OptHostsDB;
@@ -72,6 +73,8 @@ $OptStatsType = 'all' if !$OptStatsType;
 ### get time period from --month
 # get verbal description of time period, drop SQL code
 my ($Period) = &GetTimePeriod($OptMonth);
+# bail out if --month is invalid or set to 'ALL';
+# we don't support the latter
 &Bleat(2,"--month option has an invalid format - please use 'YYYY-MM' or ".
          "'YYYY-MM:YYYY-MM'!") if (!$Period or $Period eq 'all time');
 
@@ -121,15 +124,15 @@ foreach my $Month (&ListMonth($Period)) {
 
     ### ----------------------------------------------
     ### get groups data (number of postings per group)
-    # get groups data from raw table for given month
+    # get groups data from parsed table for given month
     my $DBQuery = $DBHandle->prepare(sprintf("SELECT newsgroups FROM %s.%s ".
                                              "WHERE day LIKE ? AND NOT disregard",
                                              $Conf{'DBDatabase'},
-                                             $Conf{'DBTableRaw'}));
+                                             $Conf{'DBTableParse'}));
     $DBQuery->execute($Month.'-%')
       or &Bleat(2,sprintf("Can't get groups data for %s from %s.%s: ".
                           "$DBI::errstr\n",$Month,
-                          $Conf{'DBDatabase'},$Conf{'DBTableRaw'}));
+                          $Conf{'DBDatabase'},$Conf{'DBTableParse'}));
 
     # count postings per group
     my %Postings;
@@ -161,7 +164,7 @@ foreach my $Month (&ListMonth($Period)) {
         }
       };
     };
-    
+
     # delete old data for that month
     if (!$OptTest) {
       $DBQuery = $DBHandle->do(sprintf("DELETE FROM %s.%s WHERE month = ?",
@@ -203,11 +206,11 @@ __END__
 
 =head1 NAME
 
-gatherstats - process statistical data from a raw source
+gatherstats - process statistical data from a parsed source
 
 =head1 SYNOPSIS
 
-B<gatherstats> [B<-Vhdt>] [B<-m> I<YYYY-MM> | I<YYYY-MM:YYYY-MM>] [B<-s> I<stats>] [B<-c> I<filename template>]] [B<--hierarchy> I<TLH>] [B<--rawdb> I<database table>] [B<-groupsdb> I<database table>] [B<--clientsdb> I<database table>] [B<--hostsdb> I<database table>]
+B<gatherstats> [B<-Vhdt>] [B<-m> I<YYYY-MM> | I<YYYY-MM:YYYY-MM>] [B<-s> I<stats>] [B<-c> I<filename template>]] [B<--hierarchy> I<TLH>] [B<--parsedb> I<database table>] [B<-groupsdb> I<database table>] [B<--clientsdb> I<database table>] [B<--hostsdb> I<database table>] [B<--conffile> I<filename>]
 
 =head1 REQUIREMENTS
 
@@ -216,7 +219,7 @@ See L<doc/README>.
 =head1 DESCRIPTION
 
 This script will extract and process statistical information from a
-database table which is fed from F<feedlog.pl> for a given time period
+database table which is filled from F<parsedb.pl> for a given time period
 and write its results to (an)other database table(s). Entries marked
 with I<'disregard'> in the database will be ignored; currently, you
 have to set this flag yourself, using your database management tools.
@@ -258,12 +261,13 @@ override that default through the B<--groupsdb> option.
 =head2 Configuration
 
 B<gatherstats> will read its configuration from F<newsstats.conf>
-which should be present in the same directory via Config::Auto.
+which should be present in etc/ via Config::Auto or from a configuration file
+submitted by the B<--conffile> option.
 
 See L<doc/INSTALL> for an overview of possible configuration options.
 
 You can override configuration options via the B<--hierarchy>,
-B<--rawdb>, B<--groupsdb>, B<--clientsdb> and B<--hostsdb> options,
+B<--parsedb>, B<--groupsdb>, B<--clientsdb> and B<--hostsdb> options,
 respectively.
 
 =head1 OPTIONS
@@ -292,7 +296,7 @@ conjunction with B<--test> ... everything else seems a bit pointless.
 
 Set processing period to a single month in YYYY-MM format or to a time
 period between two month in YYYY-MM:YYYY-MM format (two month, separated
-by a colon). 
+by a colon).
 
 =item B<-s>, B<--stats> I<type>
 
@@ -324,9 +328,9 @@ will be added with a count of 0 (and logged to STDERR).
 
 Override I<TLH> from F<newsstats.conf>.
 
-=item B<--rawdb> I<table> (raw data table)
+=item B<--parsedb> I<table> (parsed data table)
 
-Override I<DBTableRaw> from F<newsstats.conf>.
+Override I<DBTableParse> from F<newsstats.conf>.
 
 =item B<--groupsdb> I<table> (postings per group table)
 
@@ -340,6 +344,10 @@ Override I<DBTableClnts> from F<newsstats.conf>.
 
 Override I<DBTableHosts> from F<newsstats.conf>.
 
+=item B<--conffile> I<filename>
+
+Load configuration from I<filename> instead of F<newsstats.conf>.
+
 =back
 
 =head1 INSTALLATION
@@ -410,7 +418,7 @@ Thomas Hochstein <thh@inter.net>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (c) 2010-2012 Thomas Hochstein <thh@inter.net>
+Copyright (c) 2010-2013 Thomas Hochstein <thh@inter.net>
 
 This program is free software; you may redistribute it and/or modify it
 under the same terms as Perl itself.
This page took 0.013762 seconds and 4 git commands to generate.