You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
photovoter_backend/util/import_photos.py

69 lines
1.7 KiB

# Third-party
from wand.image import Image
import filetype
# Built-in
from os import path
from sys import argv, stderr
from shutil import move
# update database residing here
DB_LOCATION = "photovoter.dblite"
# place compressed images here
DEST_STRUNK = "image/"
def usage():
"""Brief usage explanation"""
print("USAGE: ./{name} /path/to/images".format(name=argv[0]), file=stderr)
def process_pictures():
"""Process images from the base directory in the first command line argument.
Place the resized copies to DEST_STRUNK and
move the originals to DEST_ORIGINAL.
Return a dict for each image processed for database collection.
"""
# walk every pic
# We only care about files in the root of the path
# Ignore any nested directories
(root, _, filenames) = next(walk(argv[1], topdown=True), (None, None, []))
for filename in filenames:
# skip any non-image files
if not filetype.image_match(path.join(root, filename)):
continue
# process it with imagemagick
# move them to the processed folder
# update the database
pass
def update_database():
"""Append new image information to the existing database
or create a new one, if it does not exist yet
"""
# make sure the database exists
# insert new pictures to the image table
pass
def check_database():
"""Check if there is a database at DB_LOCATION.
Just return if there is. If not, create a new one.
"""
# db exists?
# make one
pass
def main():
if len(argv) != 2:
usage()
exit(1)
# process each pic and add it to the database
if __name__ == "__main__":
main()