photo-stats

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/photo-stats.git
Log | Files | Refs | README | LICENSE

commit a5a84e9ebbee82cfef18bc251928dde37596ae3f
parent 388f92481d85c173140b02135206a4a8cdfb8a02
Author: René Wagner <rwagner@rw-net.de>
Date:   Fri, 14 Aug 2020 14:16:22 +0200

introduce -d for specifying a db file

Diffstat:
Mphosta.pl | 31+++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/phosta.pl b/phosta.pl @@ -15,25 +15,27 @@ use Cwd; use DBI; use Getopt::Std; -my $driver = "SQLite"; -my $database = getcwd . "/photo_stats.db"; -my $dsn = "DBI:$driver:dbname=$database"; $Getopt::Std::STANDARD_HELP_VERSION = 'true'; -my $VERSION = '0.4'; +my $VERSION = '0.5'; my $PROGRAM = 'Photo Stats'; # read commandline switches +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:') or die "Invalid parameters provided! See 'phosta.pl --help' for more details."; +getopts('cqp:g:s:d:') or die "Invalid parameters provided! See 'phosta.pl --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_p ne '' ) { - populate_db($opt_p, $opt_c); + populate_db($opt_p); exit 0; } @@ -41,17 +43,25 @@ query_db($opt_s, $opt_g); exit 0; +sub create_db +{ + my ($dbfile) = @_; + my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr; + + my $stmt = 'CREATE TABLE photos (file TEXT PRIMARY KEY, maker TEXT, model TEXT, lens TEXT, focallength INTEGER, focallength35mm INTEGER, aperture DECIMAL, exposuretime TEXT, iso INTEGER, flash TEXT, datetimeoriginal DATETIME);'; + my $rv = $dbh->do($stmt); +} + sub populate_db { - my ($destination_dir, $clean) = @_; + my ($destination_dir) = @_; say "Scanning $destination_dir for images..."; - + my $cmd = "exiftool -fast2 -r -m -f -p '\$filepath##\$make##\$model##\$lens##\$lensmodel##\$focallength##\$focallengthin35mmformat##\$aperture##\$exposuretime##\$iso##\$flash##\$datetimeoriginal' -d \"%Y-%m-%d %H:%M:%S\" -ext jpg " . $destination_dir; my @lines = qx($cmd); my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr; - if ( $clean ) { $dbh->do('DELETE FROM photos'); } my $errorcount = 0; my $emptycount = 0; foreach (@lines) @@ -131,7 +141,7 @@ sub get_sql sub query_db { my ($selected, $grouping) = @_; - + my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr; my $total_count = $dbh->selectrow_array("SELECT count(file) from photos"); @@ -170,6 +180,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 ' -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)';