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.
This commit is contained in:
Marcus Scholz 2020-03-05 16:34:35 +01:00
parent 0ad627fb0b
commit 5404ae6437

View File

@ -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()