diff --git a/.gitignore b/.gitignore index 3e67672..41ded9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +testsource +testdest testdata usercomment.sh diff --git a/exif_rad.py b/exif_rad.py index 2e23365..13b8f08 100755 --- a/exif_rad.py +++ b/exif_rad.py @@ -38,22 +38,21 @@ parser.add_argument('-o', '--outdir', type=str, default='.', args = parser.parse_args() -# Import GeigerCounter log -with open(args.csv, "r") as f: - csvreader = csv.reader(filter(lambda row: row[0]!='#', f), delimiter=',', skipinitialspace=True) - - for photo in args.photos: - # Load Image and EXIF data - im = Image.open(photo) - exif_dict = piexif.load(im.info['exif']) - photo_basename = os.path.basename(photo) +for photo in args.photos: + # Load Image and EXIF data + im = Image.open(photo) + exif_dict = piexif.load(im.info['exif']) + photo_basename = os.path.basename(photo) + + # Import GeigerCounter log + with open(args.csv, "r") as f: + csvreader = csv.reader(filter(lambda row: row[0]!='#', f), delimiter=',', skipinitialspace=True) picrawtime = exif_dict['Exif'][piexif.ExifIFD.DateTimeOriginal].decode('ASCII') picisotime = datetime.strptime(picrawtime, "%Y:%m:%d %H:%M:%S") print('Processing file:', photo_basename, end='\r') for _, csvrawtime, csvrawcpm, _ in csvreader: csvisotime = datetime.fromisoformat(csvrawtime) - if csvisotime == picisotime: rad = round(float(csvrawcpm) * args.sifactor, 2) @@ -68,9 +67,9 @@ with open(args.csv, "r") as f: # be os aware and use the correct directory delimiter outfile = os.path.join(args.outdir, photo_basename) im.save(outfile, exif=exif_bytes) - # print output print('{:<30} {:<20} {:<22}'.format(photo_basename, str(picisotime), new_comment)) break else: print('{:<30} {:<20} {:<22}'.format(photo_basename, str(picisotime), 'NOT FOUND!')) + f.close()