add: enter processed imgs into database

main
rrr-marble 5 years ago
parent f0dc16927f
commit 691ad3ff5e

@ -9,7 +9,7 @@ from shutil import move
import sqlite3 import sqlite3
# update database residing here # update database residing here
DB_LOCATION = "../../testbox/photovoter.dblite" DB_LOCATION = "../../testbox/photovoter.dblite" # Q: any allowances for this being not OUR database?
# place compressed images here (needs to exist) # place compressed images here (needs to exist)
DEST_STRUNK = "../../testbox/image/" DEST_STRUNK = "../../testbox/image/"
# move originals here (needs to exist) # move originals here (needs to exist)
@ -33,7 +33,7 @@ def process_pictures():
# Ignore any nested directories # Ignore any nested directories
(root, _, filenames) = next(walk(argv[1], topdown=True), (None, None, [])) (root, _, filenames) = next(walk(argv[1], topdown=True), (None, None, []))
for filename in filenames: for filename in filenames:
# FIXME:what if picture with the same name already exists? # FIXME[0]:what if picture with the same name already exists?
# skip any non-image files # skip any non-image files
if not filetype.image_match(path.join(root, filename)): if not filetype.image_match(path.join(root, filename)):
continue continue
@ -66,15 +66,41 @@ def process_pictures():
} }
def update_database(): def update_database(pic_info: dict):
"""Append new image information to the existing database """Append new image information to the existing database
or create a new one, if it does not exist yet or create a new one, if it does not exist yet
Uses: DB_LOCATION Uses: DB_LOCATION
""" """
# make sure the database exists # make sure the database exists
check_database(DB_LOCATION) check_database(DB_LOCATION)
# FIXME[1]: closure it, so we open it only once?
con = sqlite3.connect(DB_LOCATION)
cur = con.cursor()
# insert new pictures to the image table # insert new pictures to the image table
pass cur.execute(
"""INSERT INTO images(resizedpath,
origpath,
date,
GPSLatitude,
GPSLatitudeRef,
GPSLongitude,
GPSLongitudeRef)
VALUES (:ResizedImage,
:OriginalImage,
:DateTimeOriginal,
:GPSLatitude,
:GPSLatitudeRef,
:GPSLongitude,
:GPSLongitudeRef)
""",
pic_info,
)
con.commit()
# FIXME[1]
con.close()
def check_database(database_path: str): def check_database(database_path: str):
@ -118,8 +144,7 @@ def main():
pics_processed = 0 pics_processed = 0
# process each pic and add it to the database # process each pic and add it to the database
for pic in process_pictures(): for pic in process_pictures():
update_database() update_database(pic)
print(pic) # just print into strout for now
pics_processed += 1 pics_processed += 1
if pics_processed == 0: if pics_processed == 0:

Loading…
Cancel
Save