67 lines
1.8 KiB
Perl
67 lines
1.8 KiB
Perl
#!/usr/bin/perl
|
|
|
|
# This file (c) 2007 Solomon Peachy is licensed under the GPLv3.
|
|
# It is being provided for illustration purposes only. USE AT YOUR OWN RISK.
|
|
|
|
# This script is an example of how to access the PO database via perl
|
|
# and make changes to stored info based on the image's embedded EXIF data.
|
|
|
|
use Image::Exif;
|
|
use Data::Dumper;
|
|
|
|
use strict;
|
|
use DBI;
|
|
|
|
my $href;
|
|
my %list;
|
|
my $exif = new Image::Exif;
|
|
|
|
my $db_user = "po_user";
|
|
my $db_pass = "po_pass";
|
|
my $dsn = "dbi:Pg:dbname=po_db";
|
|
|
|
my $dbh = DBI->connect($dsn, $db_user, $db_pass,
|
|
{ AutoCommit => 0}) || die($DBI::errstr);
|
|
$dbh->{RaiseError} = 1;
|
|
|
|
my $select = "select p.identifier, p.date_of_exposure, get_image_path(v.identifier, 0) from photo p, photo_version v where p.identifier > 1184 and v.photo = p.identifier order by p.identifier";
|
|
my $stmt = $dbh->prepare($select);
|
|
$stmt->execute();
|
|
while (my $href = $stmt->fetchrow_hashref()) {
|
|
next if ($$href{'date_of_exposure'} !~ /00:00:00/);
|
|
$list{$$href{'identifier'}} = $$href{'large_image_path'};
|
|
print "$$href{'date_of_exposure'} -- $$href{'identifier'} -> $$href{'large_image_path'}\n";
|
|
}
|
|
|
|
$stmt->finish();
|
|
|
|
$select = "update photo set date_of_exposure = ? where identifier = ?";
|
|
$stmt = $dbh->prepare($select);
|
|
|
|
foreach (keys(%list)) {
|
|
print "$_ -> $list{$_}\n";
|
|
next if ($_ == 12212);
|
|
next if ($_ == 12213);
|
|
next if (! -e "/mnt/bulk2/po/$list{$_}");
|
|
$exif->file_name("/mnt/bulk2/po/$list{$_}");
|
|
my $all_info = $exif->get_other_info();
|
|
my $datetime = $$all_info{'Image Generated'};
|
|
|
|
$datetime =~ s/(\d+):(\d+):(\d+)\s(.*)/$1-$2-$3 $4/;
|
|
|
|
print "$_ --> $datetime\n";
|
|
|
|
$stmt->execute($datetime, $_);
|
|
|
|
# foreach my $xx (keys(%$all_info)) {
|
|
# print " $xx -> $$all_info{$xx}\n";
|
|
# }
|
|
|
|
$dbh->commit();
|
|
}
|
|
|
|
$stmt->finish();
|
|
|
|
$dbh->disconnect();
|
|
|