def RenameFile(base, filename, rawFolder):
    """
    Grabs EXIF tags and renames file based on DateTimeDigitized tag info
    --------------------------------------------------------------------------
    Inputs:
    base:        Base directory for photos --> '/Users/chad/Pictures/testing'
    filename:    Old filename of raw file from camera --> 'DSC_0001.jpg'
    rawFolder:   Temp directory where images are transferred to from camera
    --------------------------------------------------------------------------    
    """
    print 'Original filename: ', filename
    try:
        picNumber = filename[len(filename)-8:len(filename)-4]
        
        # Open file, get EXIF tags, get date string and focal length
        os.chdir(rawFolder)
        f = open(filename, 'rb')
        tags = EXIF.process_file(f)
        datestr = str(tags['EXIF DateTimeDigitized'])
        focalLen = str(tags['EXIF FocalLength'])
       
        # Start parsing EXIF tags we just grabbed
        datestr = datestr.split(' ')
        dt = datestr[0]  # date
        tm = datestr[1]  # time
        
        # Date
        y = dt.split(':')[0]  # year
       
        if len(dt.split(':')[1]) < 2:  # month
            m = str('0') + dt.split(':')[1] 
        else:
            m = dt.split(':')[1]
           
        if len(dt.split(':')[2]) < 2:  # day
            d = str('0') + dt.split(':')[2] 
        else:
            d = dt.split(':')[2]
        
        # Time
        if int(tm.split(':')[0]) < 13:   # hour
            hr = tm.split(':')[0]
            ampm = 'AM'
        elif int(tm.split(':')[0]) > 12:
            hr = (int(tm.split(':')[0]) - 12)
            ampm = 'PM'
            
        min = tm.split(':')[1]   #  minute
        sec = tm.split(':')[2]   #  second
    
        # Establish new filename in form of:
        # 0000_yyyy-mm-dd_hh-mm-ss_00mm.jpg
        newName = picNumber + '_' + dt.replace(':', '-') + '_' + tm.replace(':', '-') + '_' + focalLen + 'mm.jpg'
    except:
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
        pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n    " + \
                str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
    
    FilePic(rawFolder, base, filename, newName, y, m, d)
    AddDateInfoKeywords(rawFolder, filename, base, newName, y, m, d, hr, ampm)
    WriteByLine(base, newName, y, m, d)

    Grabs EXIF tags and renames file based on DateTimeDigitized tag info
    --------------------------------------------------------------------------
    Inputs:
    base:        Base directory for photos --> '/Users/chad/Pictures/testing'
    filename:    Old filename of raw file from camera --> 'DSC_0001.jpg'
    rawFolder:   Temp directory where images are transferred to from camera
    --------------------------------------------------------------------------    
    
recipes/Python/500266_Cataloging_adding_IPTC_keywords_digital/recipe-500266.py