Connect to F-Spot and randomly grab pictures based on a tag.
authorAndrew Ruthven <andrew@etc.gen.nz>
Wed, 17 Sep 2008 00:13:57 +0000 (12:13 +1200)
committerAndrew Ruthven <andrew@etc.gen.nz>
Wed, 17 Sep 2008 00:13:57 +0000 (12:13 +1200)
display.pl [new file with mode: 0755]

diff --git a/display.pl b/display.pl
new file mode 100755 (executable)
index 0000000..16230ff
--- /dev/null
@@ -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();
+}