ref: pass global params into fn explicitly

pull/5/head
rrr-marble 4 years ago
parent 36cd3297af
commit b86efb2154

@ -23,12 +23,11 @@ def usage():
print("USAGE: python {name} /path/to/images".format(name=argv[0]), file=stderr)
def process_pictures():
def process_pictures(dest_strunk: str, dest_original: str):
"""Process images from the base directory in the first command line argument.
Place the resized copies to DEST_SHRUNK and
move the originals to DEST_ORIGINAL.
Place the resized copies to DEST_STRUNK and
move the originals to dest_original.
Return a dict for each image processed for database collection.
Uses: DEST_SHRUNK, DEST_ORIGINAL
"""
# walk every pic
# We only care about files in the root of the path
@ -50,16 +49,16 @@ def process_pictures():
cloned.strip() # Q: may damage icc, do we allow that or use smh else?
cloned.transform(resize="50%") # Q: what do we want here?
# move them to the processed folder
cloned.save(filename=path.join(DEST_SHRUNK, filename))
cloned.save(filename=path.join(dest_strunk, filename))
# move the originals out of the working directory
# Q: do we strip exif from originals?
move(path.join(root, filename), DEST_ORIGINAL)
move(path.join(root, filename), dest_original)
# return the freshly processed picture info
yield {
"ResizedImage": path.join(DEST_SHRUNK, filename),
"OriginalImage": path.join(DEST_ORIGINAL, filename),
"ResizedImage": path.join(dest_strunk, filename),
"OriginalImage": path.join(dest_original, filename),
"DateTimeOriginal": exif["DateTimeOriginal"], # Q: normalize it?
"GPSLatitude": exif["GPSLatitude"],
"GPSLatitudeRef": exif["GPSLatitudeRef"],
@ -68,16 +67,15 @@ def process_pictures():
}
def update_database(pic_info: dict):
def update_database(pic_info: dict, db_location: str):
"""Append new image information to the existing database
or create a new one, if it does not exist yet
Uses: DB_LOCATION
"""
# 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)
con = sqlite3.connect(db_location)
cur = con.cursor()
# insert new pictures to the image table
cur.execute(
@ -176,8 +174,8 @@ def main():
pics_processed = 0
# process each pic and add it to the database
for pic in process_pictures():
update_database(pic)
for pic in process_pictures(DEST_STRUNK, DEST_ORIGINAL):
update_database(pic, DB_LOCATION)
pics_processed += 1
if pics_processed == 0:

Loading…
Cancel
Save