From c5ab01ef4d8af8cbba11169fa693a55ae06aeea8 Mon Sep 17 00:00:00 2001 From: Alexander Hosking Date: Sat, 7 Jan 2023 20:19:57 -0500 Subject: [PATCH] Correct Folder creation and update Media directory --- mediacopy/file_copy.py | 45 +++++++++++++++++++++++------------------ requirements.txt | Bin 398 -> 176 bytes 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/mediacopy/file_copy.py b/mediacopy/file_copy.py index b383295..77b0944 100644 --- a/mediacopy/file_copy.py +++ b/mediacopy/file_copy.py @@ -1,11 +1,13 @@ -import os, time, sys +import os +import time +import sys from shutil import copy2 import filecmp import pathlib from PIL import Image, ExifTags import pendulum -INGEST_DIR = pathlib.PureWindowsPath(r'\\192.168.1.4\photos\z_temp\external_backup\olympus\DCIM\100OLYMP') +INGEST_DIR = pathlib.PureWindowsPath(r'E:\DCIM\103ND810') PHOTO_LIBRARY = '//192.168.1.4/photos/photo_library/' file_list = os.listdir(INGEST_DIR) # print(file_list) @@ -16,9 +18,9 @@ for item in file_list: # print(cur_file) # print("last modified: %s" % time.ctime(os.path.getmtime(cur_file))) # created_date = cur_file.stat().st_ctime - - ##Check for Exif Data - ## if no exif data revert to file created time + + # Check for Exif Data + # if no exif data revert to file created time try: created_date = Image.open(cur_file)._getexif()[36867] parsed_date = pendulum.parse(created_date) @@ -27,41 +29,44 @@ for item in file_list: parsed_date = pendulum.parse(created_date, strict=False) filename, file_extension = os.path.splitext(item) - filename = item ## Critical to the process + filename = item # Critical to the process if not file_extension.lower() == ".nef" and not file_extension.lower() == ".jpg": continue # print(filename, file_extension) # print(created_date) # print() - + # print(parsed_date) - year = parsed_date.year + year = str(parsed_date.year) month = str(parsed_date.month).zfill(2) day = str(parsed_date.day).zfill(2) destination = "%s%s/%s/%s/%s" % (PHOTO_LIBRARY, year, month, day, filename) # print(destination) - print("We want to move %s to %s%s/%s/%s." % (filename, PHOTO_LIBRARY, year, month, day)) + print("We want to move %s to %s%s/%s/%s." % + (filename, PHOTO_LIBRARY, year, month, day)) - ## check if the directory exists + # check if the directory exists if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year))): - print("We couldn't find your directory") - os.makedirs(os.path.join(PHOTO_LIBRARY, year)) + print("We couldn't find your directory.") + os.makedirs(os.path.join(PHOTO_LIBRARY, str(year))) if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month))): - print("We couldn't find your directory") + print("We couldn't find your directory, making year and month") os.makedirs(os.path.join(PHOTO_LIBRARY, str(year), str(month))) if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month), str(day))): - print("We couldn't find your directory") - os.makedirs(os.path.join(PHOTO_LIBRARY, str(year), str(month), str(day))) + print("We couldn't find your directory, making year month and day") + os.makedirs(os.path.join(PHOTO_LIBRARY, + str(year), str(month), str(day))) - ## We should be copying, creating a source and destination hash - ## comparing the files and then deleting the source + # We should be copying, creating a source and destination hash + # comparing the files and then deleting the source print() print("Copying %s to %s" % (cur_file, destination)) copy2(cur_file, destination) if filecmp.cmp(cur_file, destination) == True: - print("%s and %s are a match. Time to delete %s" % (cur_file, destination, cur_file)) + print("%s and %s are a match. Time to delete %s" % + (cur_file, destination, cur_file)) os.remove(cur_file) -### TODO: -### Find files with no extension and save them + directory to a file \ No newline at end of file +# TODO: +# Find files with no extension and save them + directory to a file diff --git a/requirements.txt b/requirements.txt index 8735673e2d4367274d770f1f36c691b5e4176768..14507b0d0bc01a25df9a20b24b421bffca06e075 100644 GIT binary patch literal 176 zcmX|*OA3QP5JcZv$WbCQBZRof9dZT10R=TeM)EnlvC^4HQ;X(RSM_I|iA=OC4ARI& z6DaXg;6TBZUTomT!)Ps1NzUlZi$o_naa2yDEh;J5)j#dLr~Ulz>}+zMQF1AC+z%m4rY literal 398 zcmYLFOLD^?4BhK68iV81U9idpI@1#nP;AE75J9H#?JMlgbf<^(e%PFS;9`uz3-)lc zZl+t>DyL{nhf3oW9B~bgV2tk6Cn|+{1UFmuRE_De!wa|+6Wi4`PSbHBLGK#FUALzz zcHl#4xIy6@kkjeg!Ccok99t!N3WDE6OXCP3TkpBeT39i;hDOetmMd)2ldgmBg&T3#8i&91LQqhF6XU;zQWi39Xv_k0oBmX_nOx88&E4?dcLSs zVM~@4hN<#?@Rd~Rq0Hf)7TW$5N_e-1>LS-Kj#991SPxR{hwikw