photo-stats

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

commit 388f92481d85c173140b02135206a4a8cdfb8a02
parent d4c6492b9fbfae8fae1ac8150c263d98431d2c10
Author: René Wagner <rwagner@rw-net.de>
Date:   Fri, 14 Aug 2020 13:40:55 +0200

use db in working dir instead of program dir

Diffstat:
MREADME.md | 6+++++-
Mphosta.pl | 20+++++++++-----------
2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md @@ -28,9 +28,13 @@ Additionally the following perl modules need to be installed: - Text::SimpleTable::AutoWidth ## usage +### populate the database Before getting in touch with the stats, you need to populate the database with the data of your images. Run `phosta[.pl] -p <your_image_folder>` to add the data of the images in the folder and every subfolder to the database. -To query the stats, run `phosta[.pl] -q -s <fields> -g <grouping>`. +The database will be created in the currend working dir. + +### query the database +To query the stats, simply run `phosta[.pl] -s <fields> -g <grouping>` after you've initially filled the database. For information about parameters and usage call `phosta[.pl] --help`. diff --git a/phosta.pl b/phosta.pl @@ -16,11 +16,8 @@ use DBI; use Getopt::Std; my $driver = "SQLite"; -my $database = "photo_stats.db"; +my $database = getcwd . "/photo_stats.db"; my $dsn = "DBI:$driver:dbname=$database"; -my $userid = ""; -my $password = ""; - $Getopt::Std::STANDARD_HELP_VERSION = 'true'; my $VERSION = '0.4'; @@ -37,10 +34,10 @@ getopts('cqp:g:s:') or die "Invalid parameters provided! See 'phosta.pl --help' if ( $opt_p ne '' ) { populate_db($opt_p, $opt_c); + exit 0; } -if ( $opt_q ) { - query_db($opt_s, $opt_g) -} + +query_db($opt_s, $opt_g); exit 0; @@ -53,7 +50,7 @@ sub populate_db 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, $userid, $password, { RaiseError => 1 }) or die $DBI::errstr; + my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr; if ( $clean ) { $dbh->do('DELETE FROM photos'); } my $errorcount = 0; my $emptycount = 0; @@ -135,7 +132,7 @@ sub query_db { my ($selected, $grouping) = @_; - my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die $DBI::errstr; + my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr; my $total_count = $dbh->selectrow_array("SELECT count(file) from photos"); say "Querying local database with $total_count entries..."; @@ -168,15 +165,16 @@ sub main::HELP_MESSAGE { say ''; say 'Extract the EXIF data of images (currently jpg only) and feed them to a database.'; + say 'Afterwards query some stats from the selected data.'; say ''; say 'usage: phosta(.pl) [options]'; say ''; say 'options:'; 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 : group by time range, defaults to total (which means no grouping by time range)'; + say ' -g : (query mode) group by time range, defaults to total (which means no grouping by time range)'; say ' allowed values: year, month, week'; - say ' -s : specify the information you want to select, defaults to none (just show number of images)'; + say ' -s : (query mode) specify the information you want to select, defaults to none (just show number of images)'; say ' allowed values: maker, model, lens, aperture, exposuretime, iso, focallength, focallength35mm'; say ' multiple fields should be listed comma-separated'; say ' --help : show this help';