Renamed photo class attribute.

Figured how to acces class objects.
Moved write_exif to own Exif class to compile GPS coords and write them all.
This commit is contained in:
Marcus Scholz 2020-03-12 19:24:27 +01:00
parent 2ad8b4a1fb
commit f07eb0c691
2 changed files with 20 additions and 15 deletions

View File

@ -9,7 +9,7 @@ import shutil
import pyexiv2 import pyexiv2
class Radiation: class Radiation:
''' Handles CSV processing.''' ''' Handles CSV processing. '''
def __init__(self, timestamp, radiation, local_timezone, si_factor): def __init__(self, timestamp, radiation, local_timezone, si_factor):
self.timestamp = self._time_conversion(timestamp, local_timezone) self.timestamp = self._time_conversion(timestamp, local_timezone)
self.radiation = self._radiation_conversion(radiation, si_factor) self.radiation = self._radiation_conversion(radiation, si_factor)
@ -29,13 +29,13 @@ class Radiation:
return radiation return radiation
class Photo: class Photo:
''' Reads and writes Exif metadata''' ''' Reads and writes Exif metadata. '''
def __init__(self, photo, local_timezone, dest_dir, dry_run): def __init__(self, photo, local_timezone, dest_dir, dry_run):
self.get_date = self._get_creation_date(photo, local_timezone) self.get_date = self._get_creation_date(photo, local_timezone)
self.copy_photo = self._copy_photo(photo, dest_dir, dry_run) self.get_target_photo = self._copy_photo(photo, dest_dir, dry_run)
def __repr__(self): def __repr__(self):
return 'Photo: %s Creation Date: %s' % (str(self.copy_photo), str(self.get_date)) return 'Photo: %s Creation Date: %s' % (str(self.get_target_photo), str(self.get_date))
def _copy_photo(self, photo, dest_dir, dry_run): def _copy_photo(self, photo, dest_dir, dry_run):
# Determine where to work on photo and copy it there if needed. # Determine where to work on photo and copy it there if needed.
@ -48,7 +48,7 @@ class Photo:
# if not in dry_run mode or if dest_dir is different from src_dir. # if not in dry_run mode or if dest_dir is different from src_dir.
if dry_run is True: if dry_run is True:
return photo return photo
elif dest_dir != '.': if dest_dir != '.':
shutil.copy(photo, dest_photo) shutil.copy(photo, dest_photo)
return dest_photo return dest_photo
@ -56,6 +56,7 @@ class Photo:
# Load Exif data from photo # Load Exif data from photo
metadata = pyexiv2.ImageMetadata(photo) metadata = pyexiv2.ImageMetadata(photo)
metadata.read() metadata.read()
print(metadata)
date = metadata['Exif.Photo.DateTimeOriginal'] date = metadata['Exif.Photo.DateTimeOriginal']
# date.value creates datetime object in pic_naive_time # date.value creates datetime object in pic_naive_time
pic_naive_time = date.value pic_naive_time = date.value
@ -63,12 +64,14 @@ class Photo:
pic_aware_time = pic_naive_time.astimezone(local_timezone) pic_aware_time = pic_naive_time.astimezone(local_timezone)
return pic_aware_time return pic_aware_time
def write_exif(self, photo, radiation, latitude, longitude, dry_run): class Exif:
''' Compiles and writes Exif-Tags from given values. '''
def write_exif(photo, radiation, latitude, longitude, dry_run):
''' UNTESTED ! ''' ''' UNTESTED ! '''
metadata = pyexiv2.ImageMetadata(photo) metadata = pyexiv2.ImageMetadata(photo)
metadata.read()
# Set new UserComment # Set new UserComment
new_comment = 'Radiation ☢ ' + str(radiation) + ' µS/h' new_comment = 'Radiation ☢ ' + str(radiation) + ' µS/h'
# Exif tags to write # Exif tags to write

View File

@ -6,6 +6,7 @@ DateTimeOriginal from Exif tag to DateTime in a csv log
of a GeigerMuellerCounter and writes its value to the UserComment of a GeigerMuellerCounter and writes its value to the UserComment
Exif tag in µS/h ''' Exif tag in µS/h '''
from datetime import datetime
import csv import csv
import argparse import argparse
import pytz import pytz
@ -74,10 +75,9 @@ if args.gpx is not None:
for track in gpx_reader.tracks: for track in gpx_reader.tracks:
for segment in track.segments: for segment in track.segments:
for point in segment.points: for point in segment.points:
position = [point.time, point.latitude, point.longitude] position = [point.time, point.latitude, point.longitude, point.elevation]
position_list.append(position) position_list.append(position)
#print(position_list) # print(position_list)
# Inform the user about what is going to happen # Inform the user about what is going to happen
if args.dry is True: if args.dry is True:
@ -90,13 +90,15 @@ else:
for src_photo in args.photos: for src_photo in args.photos:
photo = Photo(src_photo, local_timezone, args.outdir, args.dry) photo = Photo(src_photo, local_timezone, args.outdir, args.dry)
print(photo) print(photo.get_target_photo, photo.get_date)
# Here the matching magic has to happen # Here the matching magic has to happen
latitude = '51.0234024'
longitude = '7.248347'
radiation = '9001'
# Write exif data # Write exif data
# exif_tags = Photo.write_exif(photo, radiation, latitude, longitude, args.dry) #exif_tags = Photo.write_exif(photo.get_target_photo, radiation, latitude, longitude, args.dry)
# print(exif_tags) #print(exif_tags)
# Print table header # Print table header
print('{:<15} {:<25} {:<22}'.format('filename', 'date / time', 'Exif UserComment')) print('{:<15} {:<25} {:<22}'.format('filename', 'date / time', 'Exif UserComment'))