From 5b420e80f829c3f36f2dcff121fbf82eae2871cd Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Wed, 17 Sep 2008 12:13:57 +1200 Subject: [PATCH 1/1] Connect to F-Spot and randomly grab pictures based on a tag. --- display.pl | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 display.pl diff --git a/display.pl b/display.pl new file mode 100755 index 0000000..16230ff --- /dev/null +++ b/display.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl -w + +use DBI; + +my $f_spot_db = "/home/andrew/.gnome2/f-spot/photos.db"; + + +my ($dbh, $sth) = init(); + +while (1) { + print fetch_uri($sth) . "\n"; + sleep 10; +} + +finish($dbh, $sth); + + +sub fetch_uri { + my $sth = shift; + + my $uri; + $sth->bind_columns(\$uri); + my $rc = $sth->execute() + || die "Failed to execute statement: $DBI::errstr\n"; + + $sth->fetch; + + $sth->finish() + || die "Failed to finish statement: $DBI::errstr\n";; + + return $uri; +} + +sub init { + my $dbh = DBI->connect("dbi:SQLite:dbname=$f_spot_db","","") + || die "Failed to connect to $f_spot_db: $DBI::errstr\n"; + + my $sql = " +SELECT uri +FROM photos, photo_tags, tags + WHERE photos.id = photo_tags.photo_id + AND photo_tags.tag_id = tags.id + AND tags.name = 'Brooke' +ORDER BY random() +LIMIT 1 +"; + + my $sth = $dbh->prepare($sql) + || die "Failed to prepare statement: $DBI::errstr\n"; + + return ($dbh, $sth); +} + +sub finish { + my ($dbh, $sth) = @_; + + $dbh->disconnect(); +} -- 2.30.2