Directly create datetime object from tag.value, instead of ASCII export and datetime import.

This commit is contained in:
Marcus Scholz 2020-03-04 15:44:18 +01:00
parent 6e8aaf3338
commit b4c6448645
2 changed files with 6 additions and 7 deletions

View File

@ -11,7 +11,6 @@ It then creates a `UserComment` Exif tag with the actual measured radiation at t
## Dependencies
Right now it depends on the following non-core Python 3 libraries:
* [piexif](https://pypi.org/project/pyexif/): Python module for working with EXIF image data.
* [py3exiv2](https://pypi.org/project/py3exiv2/) A Python 3 binding to the library exiv2.
* [boost.python3](http://www.boost.org/libs/python/doc/index.html) Welcome to Boost.Python, a C++ library which enables seamless interoperability between C++ and the Python programming language.
* [exiv2](http://www.exiv2.org/) Exiv2 is a Cross-platform C++ library and a command line utility to manage image metadata.

View File

@ -41,7 +41,8 @@ for photo in args.photos:
metadata = pyexiv2.ImageMetadata(photo)
metadata.read()
tag = metadata['Exif.Photo.DateTimeOriginal']
picrawtime = tag.raw_value
# tag.value creates datetime object in pictime
pictime = tag.value
# Get image file name out of path
photo_basename = os.path.basename(photo)
@ -50,12 +51,11 @@ for photo in args.photos:
csvreader = csv.reader(filter(lambda row: row[0] != '#', f),
delimiter=',', skipinitialspace=True)
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)
csvtime = datetime.fromisoformat(csvrawtime)
# Process image if its timestamp is found in CSV log
if csvisotime == picisotime:
if csvtime == pictime:
rad = round(float(csvrawcpm) * args.sifactor, 2)
# convert str to exif compatible string
@ -70,9 +70,9 @@ for photo in args.photos:
outfile = os.path.join(args.outdir, photo_basename)
# write target file
# print output
print('{:<30} {:<20} {:<22}'.format(photo_basename, str(picisotime), new_comment))
print('{:<30} {:<20} {:<22}'.format(photo_basename, str(pictime), new_comment))
break
else:
print('{:<30} {:<20} {:<22}'.format(photo_basename, str(picisotime), 'NOT FOUND!'))
print('{:<30} {:<20} {:<22}'.format(photo_basename, str(pictime), 'NOT FOUND!'))
# close CSV file
f.close()