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:
parent
2ad8b4a1fb
commit
f07eb0c691
17
functions.py
17
functions.py
@ -9,7 +9,7 @@ import shutil
|
||||
import pyexiv2
|
||||
|
||||
class Radiation:
|
||||
''' Handles CSV processing.'''
|
||||
''' Handles CSV processing. '''
|
||||
def __init__(self, timestamp, radiation, local_timezone, si_factor):
|
||||
self.timestamp = self._time_conversion(timestamp, local_timezone)
|
||||
self.radiation = self._radiation_conversion(radiation, si_factor)
|
||||
@ -29,13 +29,13 @@ class Radiation:
|
||||
return radiation
|
||||
|
||||
class Photo:
|
||||
''' Reads and writes Exif metadata'''
|
||||
''' Reads and writes Exif metadata. '''
|
||||
def __init__(self, photo, local_timezone, dest_dir, dry_run):
|
||||
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):
|
||||
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):
|
||||
# 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 dry_run is True:
|
||||
return photo
|
||||
elif dest_dir != '.':
|
||||
if dest_dir != '.':
|
||||
shutil.copy(photo, dest_photo)
|
||||
return dest_photo
|
||||
|
||||
@ -56,6 +56,7 @@ class Photo:
|
||||
# Load Exif data from photo
|
||||
metadata = pyexiv2.ImageMetadata(photo)
|
||||
metadata.read()
|
||||
print(metadata)
|
||||
date = metadata['Exif.Photo.DateTimeOriginal']
|
||||
# date.value creates datetime object in pic_naive_time
|
||||
pic_naive_time = date.value
|
||||
@ -63,12 +64,14 @@ class Photo:
|
||||
pic_aware_time = pic_naive_time.astimezone(local_timezone)
|
||||
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 ! '''
|
||||
|
||||
metadata = pyexiv2.ImageMetadata(photo)
|
||||
|
||||
metadata.read()
|
||||
# Set new UserComment
|
||||
new_comment = 'Radiation ☢ ' + str(radiation) + ' µS/h'
|
||||
# Exif tags to write
|
||||
|
18
rad_tag.py
18
rad_tag.py
@ -6,6 +6,7 @@ DateTimeOriginal from Exif tag to DateTime in a csv log
|
||||
of a GeigerMuellerCounter and writes its value to the UserComment
|
||||
Exif tag in µS/h '''
|
||||
|
||||
from datetime import datetime
|
||||
import csv
|
||||
import argparse
|
||||
import pytz
|
||||
@ -74,10 +75,9 @@ if args.gpx is not None:
|
||||
for track in gpx_reader.tracks:
|
||||
for segment in track.segments:
|
||||
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)
|
||||
#print(position_list)
|
||||
|
||||
# print(position_list)
|
||||
|
||||
# Inform the user about what is going to happen
|
||||
if args.dry is True:
|
||||
@ -90,13 +90,15 @@ else:
|
||||
|
||||
for src_photo in args.photos:
|
||||
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
|
||||
|
||||
latitude = '51.0234024'
|
||||
longitude = '7.248347'
|
||||
radiation = '9001'
|
||||
# Write exif data
|
||||
# exif_tags = Photo.write_exif(photo, radiation, latitude, longitude, args.dry)
|
||||
# print(exif_tags)
|
||||
#exif_tags = Photo.write_exif(photo.get_target_photo, radiation, latitude, longitude, args.dry)
|
||||
#print(exif_tags)
|
||||
|
||||
# Print table header
|
||||
print('{:<15} {:<25} {:<22}'.format('filename', 'date / time', 'Exif UserComment'))
|
||||
print('{:<15} {:<25} {:<22}'.format('filename', 'date / time', 'Exif UserComment'))
|
Loading…
Reference in New Issue
Block a user