diff --git a/exif_rad.py b/exif_rad.py index be13619..091417f 100755 --- a/exif_rad.py +++ b/exif_rad.py @@ -22,6 +22,7 @@ import piexif.helper # 600 series: 0.0065 µSv/h / CPM # 600+ series: 0.002637 µSv/h / CPM +# Configure argument parser for cli options parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='''A tool that writes radiation levels (and optionally geocoordinates) to image files @@ -44,27 +45,31 @@ with open(args.csv, "r") as f: for photo in args.photos: # Load Image and EXIF data im = Image.open(photo) - exif_dict = piexif.load(im.info["exif"]) + exif_dict = piexif.load(im.info['exif']) + photo_basename = os.path.basename(photo) - picrawtime = exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal].decode('ASCII') + picrawtime = exif_dict['Exif'][piexif.ExifIFD.DateTimeOriginal].decode('ASCII') picisotime = datetime.strptime(picrawtime, "%Y:%m:%d %H:%M:%S") - - print("Timestamp of image: ", picisotime) + print('\nProcessing file:', photo_basename) + print('Timestamp of image:', picisotime) for _, csvrawtime, csvrawcpm, _ in csvreader: csvisotime = datetime.fromisoformat(csvrawtime) if csvisotime == picisotime: rad = round(float(csvrawcpm) * args.sifactor, 2) - print("Radiation at time of photo: ", rad, "µS/h") + print('Found matching timestamp!') + print('Radiation at time of photo:', rad, 'µS/h') # convert str to exif compatible string - new_comment = "Radiation ☢ " + str(rad) + " µS/h" + new_comment = 'Radiation ☢ ' + str(rad) + ' µS/h' user_comment = piexif.helper.UserComment.dump(new_comment, encoding="unicode") exif_dict["Exif"][piexif.ExifIFD.UserComment] = user_comment # compile and write tags - print("Going to write comment: " + new_comment) + print('Going to write comment:', new_comment) exif_bytes = piexif.dump(exif_dict) - outfile = os.path.join(args.outdir, photo) + outfile = os.path.join(args.outdir, photo_basename) im.save(outfile, exif=exif_bytes) break + else: + print('Found NO matching timestamp, Not going to modify photo.')