From 5404ae64373b57ad53385c3d69b98abfdd8ad046 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Thu, 5 Mar 2020 16:34:35 +0100 Subject: [PATCH] Finalized v0.2 Added copy function to be able to place files to outdir before modification. Added verbose output about what it going to happen. Added table header for output. Removed obsolete "Processing..." message, as it was never visible. --- exif_rad.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/exif_rad.py b/exif_rad.py index 978232f..7ad52ad 100755 --- a/exif_rad.py +++ b/exif_rad.py @@ -38,6 +38,14 @@ parser.add_argument('-o', '--outdir', type=str, default='.', args = parser.parse_args() +# Inform the user about what is going to happen +if args.outdir == ".": + print('Modifying photos in place (overwrite)') +else: + print('Modifying photos in', str(args.outdir), '(copy)') +# Print table header +print('{:<15} {:<20} {:<22}'.format('filename', 'date / time', 'Exif UserComment')) + for srcphoto in args.photos: # Get image file name out of path photo_basename = os.path.basename(srcphoto) @@ -45,10 +53,8 @@ for srcphoto in args.photos: # Decide whether to modify photo in place or to copy it to outdir first # Then set the destination file as 'photo' to work on if args.outdir == ".": - print('Going to overwrite source file') photo = srcphoto else: - print('Going to copy source file to destdir and modify it there') # be os aware and use the correct directory delimiter for destfile dstphoto = os.path.join(args.outdir, photo_basename) shutil.copy(srcphoto, dstphoto) @@ -69,7 +75,7 @@ for srcphoto in args.photos: print('Processing file:', photo_basename, end='\r') for _, csvrawtime, csvrawcpm, _ in csvreader: csvtime = datetime.fromisoformat(csvrawtime) - # Process image if its timestamp is found in CSV log + # Process image if its timestamp is found in CSV log (compares 2 datetime objects) if csvtime == pictime: rad = round(float(csvrawcpm) * args.sifactor, 2) @@ -79,11 +85,11 @@ for srcphoto in args.photos: metadata[key] = pyexiv2.ExifTag(key, new_comment) # print found radiation levels - print('{:<30} {:<20} {:<22}'.format(photo_basename, str(pictime), new_comment)) + print('{:<15} {:<20} {:<22}'.format(photo_basename, str(pictime), new_comment)) # Write Exif tags to file metadata.write() break else: - print('{:<30} {:<20} {:<22}'.format(photo_basename, str(pictime), 'NOT FOUND!')) + print('{:<15} {:<20} {:<22}'.format(photo_basename, str(pictime), 'NOT FOUND!')) # close CSV file f.close()