From c20a3994c01bddea2e3bc42a9656ac9e6c858f34 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Mon, 20 Jun 2022 00:00:55 -0700 Subject: [PATCH] Added example [skip ci] --- examples/compare_albums.py | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/compare_albums.py diff --git a/examples/compare_albums.py b/examples/compare_albums.py new file mode 100644 index 00000000..53c8f394 --- /dev/null +++ b/examples/compare_albums.py @@ -0,0 +1,42 @@ +"""Compare two albums in Photos and find the differences.""" + +import sys + +import osxphotos +import click + + +@click.command() +@click.argument("album1") +@click.argument("album2") +def compare_albums(album1, album2): + print("Loading Photos library...") + photosdb = osxphotos.PhotosDB() + album1_ = None + album2_ = None + for album in photosdb.album_info: + if album.title == album1: + album1_ = album + if album.title == album2: + album2_ = album + if album1_ is None: + print("Album 1 not found:", album1) + sys.exit(1) + if album2_ is None: + print("Album 2 not found:", album2) + sys.exit(1) + + print(f"Comparing albums: '{album1}' '{album2}'") + not_in_album2 = [photo for photo in album1_.photos if photo not in album2_.photos] + not_in_album1 = [photo for photo in album2_.photos if photo not in album1_.photos] + + print(f"Photos in '{album1}' but not in '{album2}':") + for photo in not_in_album2: + print(f" {photo.original_filename}, {photo.date}, {photo.uuid}") + print(f"Photos in '{album2}' but not in '{album1}':") + for photo in not_in_album1: + print(f" {photo.original_filename}, {photo.date}, {photo.uuid}") + + +if __name__ == "__main__": + compare_albums()