add: database existence check

main
rrr-marble 5 years ago
parent 622a58984e
commit 50a548fcc2

@ -6,6 +6,7 @@ import filetype
from os import path, walk
from sys import argv, stderr
from shutil import move
import sqlite3
# update database residing here
DB_LOCATION = "photovoter.dblite"
@ -69,17 +70,43 @@ def update_database():
or create a new one, if it does not exist yet
"""
# make sure the database exists
check_database(DB_LOCATION)
# insert new pictures to the image table
pass
def check_database():
def check_database(database_path: str):
"""Check if there is a database at DB_LOCATION.
Just return if there is. If not, create a new one.
"""
# db exists?
if path.exists(database_path):
print("DB exists, updating", database_path)
return
# make one
pass
else:
print("No DB, creating", database_path)
con = sqlite3.connect(database_path)
cur = con.cursor()
# Create table
cur.execute(
"""CREATE TABLE images
(
imgid INTEGER PRIMARY KEY,
resizedpath TEXT NOT NULL,
origpath TEXT NOT NULL,
date TEXT,
GPSLatitude TEXT,
GPSLatitudeRef TEXT,
GPSLongitude TEXT,
GPSLongitudeRef TEXT
)"""
)
con.commit()
# we only use this occasionaly with the new databases,
# so don't bother with transfer logic, just close and reopen it later
con.close()
def main():
@ -89,6 +116,7 @@ def main():
# process each pic and add it to the database
for pic in process_pictures():
update_database()
print(pic) # just print into strout for now

Loading…
Cancel
Save