photo-stats

statistics processor for the terminal
git clone https://git.clttr.info/photo-stats.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 4dff1ffa9535e8cfff4d472194c76204df03c0ed
parent a5a84e9ebbee82cfef18bc251928dde37596ae3f
Author: René Wagner <rwagner@rw-net.de>
Date:   Fri, 14 Aug 2020 19:20:50 +0200

check values of -s and -g params

Diffstat:
A.gitignore | 1+
Mphosta.pl | 29++++++++++++++++++++++-------
2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +photo_stats.db diff --git a/phosta.pl b/phosta.pl @@ -21,18 +21,18 @@ my $VERSION = '0.5'; my $PROGRAM = 'Photo Stats'; # read commandline switches -our $opt_d=getcwd . "/photo_stats.db"; +our $opt_D=getcwd . "/photo_stats.db"; our $opt_p=''; our $opt_c=0; -our $opt_q=0; our $opt_s=''; our $opt_g=''; -getopts('cqp:g:s:d:') or die "Invalid parameters provided! See 'phosta.pl --help' for more details."; -my $dsn = "DBI:SQLite:dbname=$opt_d"; +getopts('cp:g:s:d:') or die "Invalid parameters provided! See 'phosta --help' for more details."; +validate() or die "Invalid parameters provided! See 'phosta --help' for more details."; +my $dsn = "DBI:SQLite:dbname=$opt_D"; -if ($opt_c) { unlink $opt_d; } -if ( !-e $opt_d ) { create_db($opt_d) or die 'database could not be created'; } +if ($opt_c) { unlink $opt_D; } +if ( !-e $opt_D ) { create_db($opt_D) or die 'database could not be created'; } if ( $opt_p ne '' ) { populate_db($opt_p); @@ -43,6 +43,20 @@ query_db($opt_s, $opt_g); exit 0; +sub validate +{ + my @group_params = ('year', 'month', 'week', ''); + if ( ! ($opt_g ~~ @group_params) ) { return 0; } + + my @select_params = ('maker', 'model', 'lens', 'aperture', 'exposuretime', 'iso', 'focallength', 'focallength35mm', ''); + foreach (split (/,/, $opt_s)) + { + if ( ! ($_ ~~ @select_params) ) { return 0; } + } + + return 1; +} + sub create_db { my ($dbfile) = @_; @@ -82,6 +96,7 @@ sub populate_db $dbh->disconnect(); say sprintf('%5d', $emptycount). ' image files skipped due to missing EXIF data'; say sprintf('%5d', $errorcount). ' image files skipped due to errors'; + say "Updated local database $opt_D."; } sub get_sql @@ -180,7 +195,7 @@ sub main::HELP_MESSAGE say 'usage: phosta(.pl) [options]'; say ''; say 'options:'; - say ' -d <file> : path and name of the db file to use'; + say ' -D <file> : path and name of the db file to use'; say ' -p <folder> : populate database from the files in the specified folder'; say ' -c : clear the database before populating with data from the folder'; say ' -g : (query mode) group by time range, defaults to total (which means no grouping by time range)';