#!/usr/bin/env python

import hashlib
from datetime import datetime
import os
import shutil

from PIL import Image


def rename_file(file_name):
    with open(file_name, 'rb') as f:
        checksum = hashlib.sha1()
        while chunk := f.read(8192):
            checksum.update(chunk)
        im = Image.open(f)
        date = datetime.strptime(im._getexif()[36867], "%Y:%m:%d %H:%M:%S")
        print()
        ext = os.path.splitext(file_name)[1]
    
    basedir = os.path.dirname(file_name)
    new_name = f"{date.strftime('%Y%m%d_%H%M%S')}_{checksum.hexdigest()}{ext}"
    new_path = f"{basedir}/{date.year}/{date.month}"
    
    os.makedirs(new_path)
    shutil.move(file_name, f"{new_path}/{new_name}")
    return new_path

#!/usr/bin/env python

import hashlib
from datetime import datetime
import os
import shutil

from PIL import Image


def rename_file(file_name):
    with open(file_name, 'rb') as f:
        checksum = hashlib.sha1()
        while chunk := f.read(8192):
            checksum.update(chunk)
        im = Image.open(f)
        date = datetime.strptime(im._getexif()[36867], "%Y:%m:%d %H:%M:%S")
        print()
        ext = os.path.splitext(file_name)[1]
    
    basedir = os.path.dirname(file_name)
    new_name = f"{date.strftime('%Y%m%d_%H%M%S')}_{checksum.hexdigest()}{ext}"
    new_path = f"{basedir}/{date.year}/{date.month}"
    
    os.makedirs(new_path)
    shutil.move(file_name, f"{new_path}/{new_name}")
    return new_path

#!/usr/bin/env python