Switched to use csv native lib, simplified code.

This commit is contained in:
Marcus Scholz 2020-03-01 22:03:04 +01:00
parent 32c338289f
commit 6c4626ed50

View File

@ -6,6 +6,7 @@ DateTimeOriginal from Exif tag to DateTime in a csv log
of a GeigerMuellerCounter."""
from datetime import datetime
import csv
from PIL import Image
import piexif
import piexif.helper
@ -35,24 +36,22 @@ print("Timestamp of image: ", picisotime)
# Import GeigerCounter log
with open("testdata/test.hisdb.his", "r") as f:
for line in f:
if line[0] != '#':
columns = line.split(',')
csvrawtime = columns[1].lstrip()
csvrawcpm = columns[2].lstrip()
csvisotime = datetime.fromisoformat(csvrawtime)
if csvisotime == picisotime:
rad = round(float(csvrawcpm) * SIFACTOR, 2)
print("Radiation at time of photo: ", rad, "µS/h")
csvreader = csv.reader(filter(lambda row: row[0]!='#', f), delimiter=',', skipinitialspace=True)
for _, csvrawtime, csvrawcpm, _ in csvreader:
print(csvrawtime, csvrawcpm)
csvisotime = datetime.fromisoformat(csvrawtime)
if csvisotime == picisotime:
rad = round(float(csvrawcpm) * SIFACTOR, 2)
print("Radiation at time of photo: ", rad, "µS/h")
# convert str to exif compatible string
new_comment = "Radiation ☢ " + str(rad) + " µS/h"
user_comment = piexif.helper.UserComment.dump(new_comment, encoding="unicode")
exif_dict["Exif"][piexif.ExifIFD.UserComment] = user_comment
# compile and write tags
print("Going to write comment: " + new_comment)
exif_bytes = piexif.dump(exif_dict)
im.save("testdata/test.jpg", exif=exif_bytes)
break
# convert str to exif compatible string
new_comment = "Radiation ☢ " + str(rad) + " µS/h"
user_comment = piexif.helper.UserComment.dump(new_comment, encoding="unicode")
exif_dict["Exif"][piexif.ExifIFD.UserComment] = user_comment
# compile and write tags
print("Going to write comment: " + new_comment)
exif_bytes = piexif.dump(exif_dict)
im.save("testdata/test.jpg", exif=exif_bytes)
break