Works with path

This commit is contained in:
Jeff MacKinnon 2022-10-25 21:01:45 -03:00
parent 00abf88d67
commit 2e3101182b

View file

@ -4,15 +4,15 @@
import argparse # The library that will parse the arguments.
#import os
import os
from os import listdir
from os.path import isfile, join
from os.path import isdir,isfile, join
#import PIL
from PIL import Image
from PIL.ExifTags import GPSTAGS
from PIL.ExifTags import TAGS
from fraction import Fraction
from fractions import Fraction
# Parser
@ -28,6 +28,8 @@ parser.add_argument('Path',
type=str,
help='top level path for with the images'
)
#
# Need to add the parser for what information we want to add for each
#
@ -64,12 +66,17 @@ def get_exif(image_path):
return None
# This is from J0el - https://gist.github.com/Jeffmackinnon/92c747b30a873129a28cddacfc61fbe1?permalink_comment_id=4185193#gistcomment-4185193
# A couple of minor tweaks to make it work
def exposure(ExposureTime):
try:
return( str(Fraction('ExposureTime')))
time = float(ExposureTime)
if time > 1:
return(ExposureTime)
else:
return( str(Fraction(time).limit_denominator()))
except:
return('None')
return(ExposureTime)
#Creates a text file with some exif meta data.
def write_exif_file(directory):
@ -83,11 +90,13 @@ def write_exif_file(directory):
if file.endswith(".jpg"):
# Need to iterate through the files in the list and pass each to the
image = get_exif(directory +'/'+os.path.join(file))
txt.write(
os.path.join(file) + ': ' +
str(image.get('Model')) +
str(
image.get('Model')) +
' with a ' + str(image.get('LensModel')) +
' - ' + str(image.get(exposure(ExposureTime))) + 's, ' + # I want to change this to fractions, but it works for now.
' - ' + str(exposure(image.get('ExposureTime'))) + 's, ' + # I want to change this to fractions, but it works for now.
'f/' + str(image.get('FNumber')) +
' at ISO-' + str(image.get('ISOSpeedRatings')) +
'\n'