from exif import Image

print(f"Przestrzeń 1: {__name__}")

# otwarcie pliku
def fn_file(file_name):
    try:
        with open(file_name, mode="rb") as file:
            img = Image(file)
        return img
    except Exception as e:
        print(e)
        return False

# sprawdzenie danych exif
def file_ok(image):
    if image.has_exif:
        return True
    else:
        return False

# wyciagniecie danych
def get_exif(image):
    ret = ""
    all_data = image.get_all()
    klucze = all_data.keys()
    if 'lens_model' in klucze:
        ret += f" Lens model: {all_data['lens_model']}"
    if "make" in klucze:
        ret += f" Make: {all_data['make']}"
    if "model" in klucze:
        ret += f" Model: {all_data['model']}"
    return ret



if __name__ == "__main__":
    print(fn_file("images/IMG_123311x.jpg"))

    ok = fn_file("IMG_1233.jpg")
    if ok:
        if file_ok(ok):
            print(get_exif(ok))

    print(fn_file("to-do.md"))

