Added Output class that formats matched data and returns string for printing.

Added beautified output.
This commit is contained in:
2020-03-21 17:17:42 +01:00
parent d935cc1ea0
commit c2ed0e1c2a
2 changed files with 70 additions and 14 deletions

View File

@@ -74,10 +74,10 @@ class Photo:
# Copy photo to dest_dir and return its (new) filename
# if not in dry_run mode or if dest_dir is different from src_dir.
if dry_run is True:
return photo
return photo_basename, photo
if dest_dir != '.':
shutil.copy(photo, dest_photo)
return dest_photo
return photo_basename, dest_photo
def _get_creation_date(self, photo, local_timezone):
# Load Exif data from photo
@@ -114,9 +114,14 @@ class Match:
radiation = round(self.radiation[1], 2)
else:
radiation = None
if self.position[1][3]:
altitude = round(self.position[1][3])
else:
altitude = None
return 'Radiation: %s µS/h (Δt %s) \nPosition: Lat: %s, Long: %s, Alt: %sm (Δt %s)' % \
(str(radiation), str(self.radiation[0]), str(self.position[1][1]), \
str(self.position[1][2]), str(self.position[1][3]), str(self.position[0]))
str(self.position[1][2]), altitude, str(self.position[0]))
def _find_radiation_match(self, photo_time, list):
valuelist = []
@@ -153,6 +158,7 @@ class Match:
if valuelist:
#print(min(valuelist, key=lambda x: x[0]))
return min(valuelist, key=lambda x: x[0])
# Return Nones in the same cascaded manner as if it matched.
return [None, [None, None, None, None]]
class Exif:
@@ -161,7 +167,7 @@ class Exif:
Arguments:
photo: file name of photo to modify
radiation: radiation levels in µS/h
radiation: radiation levels float
latitude: latitude as float
longitude: longitude as float
elevation: elevation as float
@@ -238,3 +244,46 @@ class Exif:
metadata.write()
return latitude_degree, longitude_degree, new_comment
class Output:
'''
Receives values to be printed, formats them and returns a string for printing.
Arguments:
radiation: radiation as float
latitude: latitude as float
longitude: longitude as float
elevation: elevation as float
Returns:
A String that can be printed in output
'''
def __init__(self, radiation, latitude, longitude, altitude):
self.get_string = self._get_string(radiation, latitude, longitude, altitude)
def __repr__(self):
return self.get_string
def _get_string(self, radiation, latitude, longitude, altitude):
# Convert values to styled strings
if radiation:
rad = '☢: %sµS/h ' % str(round(radiation, 2))
else:
rad = '☢: N/A '
if latitude and longitude:
latlon = 'Lat.: %s Long.: %s ' % (str(latitude), str(longitude))
else:
latlon = 'Lat.: N/A, Long.: N/A '
if altitude:
alt = 'Alt.: %sm' % str(round(altitude, 1))
else:
alt = 'Alt.: N/A'
data = rad + latlon + alt
# Return data string
return data