diff --git a/exif2txt.py b/exif2txt.py index 1c2ce1d..cad6e15 100644 --- a/exif2txt.py +++ b/exif2txt.py @@ -4,19 +4,19 @@ 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 -parser = argparse.ArguemntParser( prog='exif2txt', +parser = argparse.ArgumentParser( prog='exif2txt', usage='%(prog)s [options] path', allow_abbrev=False, description='Write EXIF metadata to text file.', @@ -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'