ref: pass global params into fn explicitly

main^2
rrr-marble 5 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) 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. """Process images from the base directory in the first command line argument.
Place the resized copies to DEST_SHRUNK and Place the resized copies to DEST_STRUNK and
move the originals to DEST_ORIGINAL. move the originals to dest_original.
Return a dict for each image processed for database collection. Return a dict for each image processed for database collection.
Uses: DEST_SHRUNK, DEST_ORIGINAL
""" """
# walk every pic # walk every pic
# We only care about files in the root of the path # 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.strip() # Q: may damage icc, do we allow that or use smh else?
cloned.transform(resize="50%") # Q: what do we want here? cloned.transform(resize="50%") # Q: what do we want here?
# move them to the processed folder # 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 # move the originals out of the working directory
# Q: do we strip exif from originals? # 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 # return the freshly processed picture info
yield { yield {
"ResizedImage": path.join(DEST_SHRUNK, filename), "ResizedImage": path.join(dest_strunk, filename),
"OriginalImage": path.join(DEST_ORIGINAL, filename), "OriginalImage": path.join(dest_original, filename),
"DateTimeOriginal": exif["DateTimeOriginal"], # Q: normalize it? "DateTimeOriginal": exif["DateTimeOriginal"], # Q: normalize it?
"GPSLatitude": exif["GPSLatitude"], "GPSLatitude": exif["GPSLatitude"],
"GPSLatitudeRef": exif["GPSLatitudeRef"], "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 """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
""" """
# 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? # FIXME[1]: closure it, so we open it only once?
con = sqlite3.connect(DB_LOCATION) con = sqlite3.connect(db_location)
cur = con.cursor() cur = con.cursor()
# insert new pictures to the image table # insert new pictures to the image table
cur.execute( cur.execute(
@ -176,8 +174,8 @@ 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(DEST_STRUNK, DEST_ORIGINAL):
update_database(pic) update_database(pic, DB_LOCATION)
pics_processed += 1 pics_processed += 1
if pics_processed == 0: if pics_processed == 0:

Loading…
Cancel
Save