From db5effde52af29d59253258d0a1dc54548856713 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Mon, 20 Jan 2020 08:59:52 -0800 Subject: [PATCH] Added photos_repl.py to examples --- examples/photos_repl.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 examples/photos_repl.py diff --git a/examples/photos_repl.py b/examples/photos_repl.py new file mode 100755 index 00000000..322de755 --- /dev/null +++ b/examples/photos_repl.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 -i + +# open an interactive REPL with photosdb and photos defined +# as osxphotos.PhotosDB() and PhotosDB.photos respectively +# useful for debugging or exploring the Photos database + +import sys + +# click needed since this uses a couple of functions from CLI (__main__.py) +import click + +import osxphotos +from osxphotos.__main__ import get_photos_db, _list_libraries + + +def main(): + db = None + + if len(sys.argv) > 1: + db = sys.argv[1] + else: + db = get_photos_db() + + if db: + return osxphotos.PhotosDB(dbfile=db) + else: + _list_libraries() + sys.exit() + + +if __name__ == "__main__": + print(f"Version: {osxphotos._version.__version__}") + photosdb = main() + photos = photosdb.photos(images=True, movies=True)