Skip to content

Instantly share code, notes, and snippets.

@mrbidon
Created December 4, 2017 06:50
Show Gist options
  • Save mrbidon/8715c5aaba5d5178466c9859e43852bf to your computer and use it in GitHub Desktop.
Save mrbidon/8715c5aaba5d5178466c9859e43852bf to your computer and use it in GitHub Desktop.
Shotwell export from a given tag
# -*- coding: utf-8 -*-
import sqlite3
import sys
#
# Shotwell export from a tag
#
# This script read the shotwell db to generate an export script of all the files
# associated to a following tag in a specified directory
#
# Command example :
# -----------------
""
# python3 copy_photo_of_a_tag.py /home/mylogin/.local/share/shotwell/data/photo.db output_dir > cp_list
# chmod u+x cp_list
# ./cp _list
def get_photo_list(cur, tag):
cur.execute("SELECT photo_id_list FROM TagTable WHERE name = '{}'".format(tag))
photo_list_id = cur.fetchone()
return photo_list_id[0].split(",")
def main(db_filename, tag, output_dir):
con = sqlite3.connect(db_filename)
cur = con.cursor()
for photo_id_str in get_photo_list(cur, tag):
if photo_id_str [0:len("thumb")] == "thumb" :
photo_id = int(photo_id_str[len("thumb"):], 16)
cur.execute("select filename from PhotoTable where id = {}".format(photo_id))
filename = cur.fetchone()
print('cp "{}" "{}"'.format(filename[0], output_dir))
if __name__ == "__main__" :
if len(sys.argv) != 4 :
print("""you must provide the folowing argument
- dbfile : file where the shotwell db is stored
- tag : tag to look for
- output_dir : output_dir where the photo will be copied
""")
else:
main(sys.argv[1], sys.argv[2], sys.argv[3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment