Skip to content

Instantly share code, notes, and snippets.

@garex
Created February 9, 2014 13:20
Show Gist options
  • Save garex/8898973 to your computer and use it in GitHub Desktop.
Save garex/8898973 to your computer and use it in GitHub Desktop.
Shotwell / Set event's key photos by max raiting (put it to ~/.shotwell/data/update-key-events-photos-by-rating.sh)
#!/usr/bin/env bash
function sql() {
local sql=$1
sqlite3 photo.db "$sql"
}
function go_to_current_directory() {
cd "$(dirname "$0")"
}
function find_all_active_event_ids() {
sql 'SELECT DISTINCT event_id FROM PhotoTable'
}
function find_best_photo_id_by_event() {
local event_id=$1
sql "SELECT id FROM PhotoTable WHERE event_id = $event_id ORDER BY rating DESC, exposure_time LIMIT 1"
}
function update_event_key_photo() {
local event_id=$1
local photo_id=$(find_best_photo_id_by_event $event_id)
local thumb_id=$(printf '%s%016x' 'thumb' $photo_id)
echo "Updating event #$event_id"
sql "UPDATE EventTable SET primary_source_id = '$thumb_id' WHERE id = $event_id"
}
function main() {
go_to_current_directory
for event_id in $(find_all_active_event_ids)
do
update_event_key_photo $event_id
done
}
main
@garex
Copy link
Author

garex commented Feb 9, 2014

Needs improvement as update_event_key_photo is a SQL that opens DB/updates it in loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment