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 os import path, walk
from sys import argv, stderr from sys import argv, stderr
from shutil import move from shutil import move
import sqlite3
# update database residing here # update database residing here
DB_LOCATION = "photovoter.dblite" DB_LOCATION = "photovoter.dblite"
@ -69,17 +70,43 @@ def update_database():
or create a new one, if it does not exist yet or create a new one, if it does not exist yet
""" """
# make sure the database exists # make sure the database exists
check_database(DB_LOCATION)
# insert new pictures to the image table # insert new pictures to the image table
pass pass
def check_database(): def check_database(database_path: str):
"""Check if there is a database at DB_LOCATION. """Check if there is a database at DB_LOCATION.
Just return if there is. If not, create a new one. Just return if there is. If not, create a new one.
""" """
# db exists? # db exists?
if path.exists(database_path):
print("DB exists, updating", database_path)
return
# make one # 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(): def main():
@ -89,6 +116,7 @@ def main():
# 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()
print(pic) # just print into strout for now print(pic) # just print into strout for now

Loading…
Cancel
Save