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