Refactored variable names, fixed dry run decision.
This commit is contained in:
parent
314e70faa9
commit
d51c28b753
46
rad_tag.py
46
rad_tag.py
@ -14,7 +14,7 @@ import argparse
|
||||
import pytz
|
||||
import pyexiv2
|
||||
import gpxpy
|
||||
from functions import Radiation, Position
|
||||
from functions import Radiation
|
||||
|
||||
# SIFACTOR for GQ Geiger counters
|
||||
|
||||
@ -53,54 +53,52 @@ args = parser.parse_args()
|
||||
local_timezone = pytz.timezone(args.timezone)
|
||||
|
||||
# Inform the user about what is going to happen
|
||||
if args.dry is not None:
|
||||
if args.dry is True:
|
||||
print('Not modifying anything. Just print what would happen without --dry')
|
||||
else:
|
||||
if args.outdir == ".":
|
||||
print('Modifying photos in place (overwrite)')
|
||||
else:
|
||||
print('Modifying photos in', str(args.outdir), '(copy)')
|
||||
else:
|
||||
print('Not modifying anything. Just print what would happen without --dry')
|
||||
|
||||
# Print table header
|
||||
print('{:<15} {:<25} {:<22}'.format('filename', 'date / time', 'Exif UserComment'))
|
||||
|
||||
for srcphoto in args.photos:
|
||||
for src_photo in args.photos:
|
||||
# Get image file name out of path
|
||||
photo_basename = os.path.basename(srcphoto)
|
||||
photo_basename = os.path.basename(src_photo)
|
||||
|
||||
# Decide whether to modify photo in place or to copy it to outdir first
|
||||
# Then set the destination file as 'photo' to work on
|
||||
if args.outdir == ".":
|
||||
photo = srcphoto
|
||||
photo = src_photo
|
||||
else:
|
||||
# be os aware and use the correct directory delimiter for destfile
|
||||
dstphoto = os.path.join(args.outdir, photo_basename)
|
||||
dst_photo = os.path.join(args.outdir, photo_basename)
|
||||
# Don't copy image if in dry-run mode
|
||||
if args.dry == 'True':
|
||||
shutil.copy(srcphoto, dstphoto)
|
||||
photo = dstphoto
|
||||
shutil.copy(src_photo, dst_photo)
|
||||
photo = dst_photo
|
||||
else:
|
||||
photo = srcphoto
|
||||
photo = src_photo
|
||||
|
||||
# Load Exif data from image
|
||||
metadata = pyexiv2.ImageMetadata(photo)
|
||||
metadata.read()
|
||||
tag = metadata['Exif.Photo.DateTimeOriginal']
|
||||
# tag.value creates datetime object in pictime
|
||||
picnaivetime = tag.value
|
||||
pic_naive_time = tag.value
|
||||
# Set timezone
|
||||
pictime = picnaivetime.astimezone(local_timezone)
|
||||
pic_time = pic_naive_time.astimezone(local_timezone)
|
||||
|
||||
# Initialize two empty lists for comparison
|
||||
radiation_list = []
|
||||
position_list = []
|
||||
|
||||
# Import GeigerCounter log
|
||||
with open(args.csv, "r") as f:
|
||||
csvreader = csv.reader(filter(lambda row: row[0] != '#', f),
|
||||
delimiter=',', skipinitialspace=True)
|
||||
csv_reader = csv.reader(filter(lambda row: row[0] != '#', f),
|
||||
delimiter=',', skipinitialspace=True)
|
||||
|
||||
for _, csvrawtime, csvrawcpm, _ in csvreader:
|
||||
radiation = Radiation(csvrawtime, csvrawcpm, local_timezone, args.sifactor)
|
||||
for _, csv_raw_time, csv_raw_cpm, _ in csv_reader:
|
||||
radiation = Radiation(csv_raw_time, csv_raw_cpm, local_timezone, args.sifactor)
|
||||
radiation_list.append(radiation)
|
||||
#print(radiation_list)
|
||||
|
||||
@ -110,13 +108,15 @@ for srcphoto in args.photos:
|
||||
# Import GPX track(s)
|
||||
if args.gpx is not None:
|
||||
gpx_file = open(args.gpx, 'r')
|
||||
gpxreader = gpxpy.parse(gpx_file)
|
||||
gpx_reader = gpxpy.parse(gpx_file)
|
||||
|
||||
for waypoint in gpxreader.waypoints:
|
||||
for track in gpxreader.tracks:
|
||||
for waypoint in gpx_reader.waypoints:
|
||||
for track in gpx_reader.tracks:
|
||||
for segment in track.segments:
|
||||
for point in segment.points:
|
||||
position = [point.time, point.latitude, point.longitude]
|
||||
position_list.append(position)
|
||||
#print(position_list)
|
||||
|
||||
# Print table header
|
||||
print('{:<15} {:<25} {:<22}'.format('filename', 'date / time', 'Exif UserComment'))
|
||||
|
Loading…
Reference in New Issue
Block a user