This repository has been archived by the owner on Jun 21, 2018. It is now read-only.
forked from fasaxc/shotwell-iphoto-import
-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.py
51 lines (47 loc) · 2.14 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# The BackingPhotoTable
# id = 1
# filepath = /home/shaun/Pictures/Photos/2008/03/24/DSCN2416 (Modified (2))_modified.JPG
# timestamp = 1348968706
# filesize = 1064375
# width = 1600
# height = 1200
# original_orientation = 1
# file_format = 0
# time_created = 1348945103
class BackingPhotoTable:
def __init__(self, db):
self.db = db
self.init()
def insert(self, photo):
cursor = self.db.execute("""
INSERT INTO BackingPhotoTable (filepath,
timestamp,
filesize,
width,
height,
original_orientation,
file_format,
time_created)
VALUES (:new_mod_path,
:mod_timestamp,
:mod_file_size,
:mod_width,
:mod_height,
:mod_original_orientation,
:file_format,
:time_created)
""", photo)
return cursor.lastrowid
def init(self):
cursor = self.db.execute("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='BackingPhotoTable'")
if (cursor.fetchone()[0] == 0):
self.db.execute("CREATE TABLE BackingPhotoTable ("
"id INTEGER PRIMARY KEY, "
"filepath TEXT UNIQUE NOT NULL, "
"timestamp INTEGER, filesize INTEGER, "
"width INTEGER, "
"height INTEGER, "
"original_orientation INTEGER, "
"file_format INTEGER, "
"time_created INTEGER "
")")