--- /dev/null
+#!/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();
+}