min event delta is configurable via parameter now =)

This commit is contained in:
Lukas 2017-11-30 22:48:57 +01:00
parent 26c334f654
commit caf9b84a26
2 changed files with 7 additions and 5 deletions

View File

@ -4,7 +4,6 @@ from time import localtime, strftime, strptime, mktime
import shutil
import exifread
minEventDelta = 60 * 60 * 24 * 4 # 4 days in seconds
unknownDateFolderName = "date-unknown"
def getMinimumCreationTime(exif_data):
@ -69,7 +68,8 @@ def createUnknownDateFolder(destinationRoot):
path = os.path.join(destinationRoot, unknownDateFolderName)
createPath(path)
def writeImages(images, destinationRoot, splitByMonth=False):
def writeImages(images, destinationRoot, minEventDeltaDays, splitByMonth=False):
minEventDelta = minEventDeltaDays * 60 * 60 * 24 # convert in seconds
sortedImages = sorted(images)
previousTime = None
eventNumber = 0
@ -117,10 +117,10 @@ def writeImages(images, destinationRoot, splitByMonth=False):
os.remove(imageTuple[1])
def postprocessImages(imageDirectory, splitByMonth):
def postprocessImages(imageDirectory, minEventDeltaDays, splitByMonth):
images = []
for root, dirs, files in os.walk(imageDirectory):
for file in files:
postprocessImage(images, imageDirectory, file)
writeImages(images, imageDirectory, splitByMonth)
writeImages(images, imageDirectory, minEventDeltaDays, splitByMonth)

View File

@ -56,6 +56,7 @@ def get_args():
parser.add_argument('-n', '--max-per-dir', type=int, default=500, required=False, help='maximum number of files per directory')
parser.add_argument('-m', '--split-months', action='store_true', required=False, help='split JPEG files not only by year but by month as well')
parser.add_argument('-k', '--keep_filename', action='store_true', required=False, help='keeps the original filenames when copying')
parser.add_argument('-d', '--min-event-delta', type=int, default=4, required=False, help='minimum delta in days between two days')
return parser.parse_args()
@ -74,6 +75,7 @@ destination = args.destination
maxNumberOfFilesPerFolder = args.max_per_dir
splitMonths = args.split_months
keepFilename = args.keep_filename
minEventDeltaDays = args.min_event_delta
print("Reading from source '%s', writing to destination '%s' (max %i files per directory, splitting by year %s)." %
(source, destination, maxNumberOfFilesPerFolder, splitMonths and "and month" or "only"))
@ -118,7 +120,7 @@ for root, dirs, files in os.walk(source, topdown=False):
log(str(fileCounter) + " / " + totalAmountToCopy + " processed.")
log("start special file treatment")
jpgSorter.postprocessImages(os.path.join(destination, "JPG"), splitMonths)
jpgSorter.postprocessImages(os.path.join(destination, "JPG"), minEventDeltaDays, splitMonths)
log("assure max file per folder number")
numberOfFilesPerFolderLimiter.limitFilesPerFolder(destination, maxNumberOfFilesPerFolder)