Correct Folder creation and update Media directory
This commit is contained in:
parent
80fd76c485
commit
c5ab01ef4d
@ -1,11 +1,13 @@
|
|||||||
import os, time, sys
|
import os
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
from shutil import copy2
|
from shutil import copy2
|
||||||
import filecmp
|
import filecmp
|
||||||
import pathlib
|
import pathlib
|
||||||
from PIL import Image, ExifTags
|
from PIL import Image, ExifTags
|
||||||
import pendulum
|
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/'
|
PHOTO_LIBRARY = '//192.168.1.4/photos/photo_library/'
|
||||||
file_list = os.listdir(INGEST_DIR)
|
file_list = os.listdir(INGEST_DIR)
|
||||||
# print(file_list)
|
# print(file_list)
|
||||||
@ -17,8 +19,8 @@ for item in file_list:
|
|||||||
# print("last modified: %s" % time.ctime(os.path.getmtime(cur_file)))
|
# print("last modified: %s" % time.ctime(os.path.getmtime(cur_file)))
|
||||||
# created_date = cur_file.stat().st_ctime
|
# created_date = cur_file.stat().st_ctime
|
||||||
|
|
||||||
##Check for Exif Data
|
# Check for Exif Data
|
||||||
## if no exif data revert to file created time
|
# if no exif data revert to file created time
|
||||||
try:
|
try:
|
||||||
created_date = Image.open(cur_file)._getexif()[36867]
|
created_date = Image.open(cur_file)._getexif()[36867]
|
||||||
parsed_date = pendulum.parse(created_date)
|
parsed_date = pendulum.parse(created_date)
|
||||||
@ -27,7 +29,7 @@ for item in file_list:
|
|||||||
parsed_date = pendulum.parse(created_date, strict=False)
|
parsed_date = pendulum.parse(created_date, strict=False)
|
||||||
|
|
||||||
filename, file_extension = os.path.splitext(item)
|
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":
|
if not file_extension.lower() == ".nef" and not file_extension.lower() == ".jpg":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -36,32 +38,35 @@ for item in file_list:
|
|||||||
# print()
|
# print()
|
||||||
|
|
||||||
# print(parsed_date)
|
# print(parsed_date)
|
||||||
year = parsed_date.year
|
year = str(parsed_date.year)
|
||||||
month = str(parsed_date.month).zfill(2)
|
month = str(parsed_date.month).zfill(2)
|
||||||
day = str(parsed_date.day).zfill(2)
|
day = str(parsed_date.day).zfill(2)
|
||||||
destination = "%s%s/%s/%s/%s" % (PHOTO_LIBRARY, year, month, day, filename)
|
destination = "%s%s/%s/%s/%s" % (PHOTO_LIBRARY, year, month, day, filename)
|
||||||
# print(destination)
|
# 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))):
|
if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year))):
|
||||||
print("We couldn't find your directory")
|
print("We couldn't find your directory.")
|
||||||
os.makedirs(os.path.join(PHOTO_LIBRARY, year))
|
os.makedirs(os.path.join(PHOTO_LIBRARY, str(year)))
|
||||||
if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month))):
|
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)))
|
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))):
|
if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month), str(day))):
|
||||||
print("We couldn't find your directory")
|
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)))
|
os.makedirs(os.path.join(PHOTO_LIBRARY,
|
||||||
|
str(year), str(month), str(day)))
|
||||||
|
|
||||||
## We should be copying, creating a source and destination hash
|
# We should be copying, creating a source and destination hash
|
||||||
## comparing the files and then deleting the source
|
# comparing the files and then deleting the source
|
||||||
print()
|
print()
|
||||||
print("Copying %s to %s" % (cur_file, destination))
|
print("Copying %s to %s" % (cur_file, destination))
|
||||||
copy2(cur_file, destination)
|
copy2(cur_file, destination)
|
||||||
if filecmp.cmp(cur_file, destination) == True:
|
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)
|
os.remove(cur_file)
|
||||||
|
|
||||||
### TODO:
|
# TODO:
|
||||||
### Find files with no extension and save them + directory to a file
|
# Find files with no extension and save them + directory to a file
|
||||||
|
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Loading…
Reference in New Issue
Block a user