From bf8aed69cfff61733e4cfd5ed2058bb20e3f5299 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 14 Dec 2019 10:35:39 -0800 Subject: [PATCH] Updated export example --- README.md | 54 +++++++++++++++++++++++++--------------------- examples/export.py | 26 ++++++++++++---------- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 2290c95c..8fe967d0 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,35 @@ if __name__ == "__main__": main() ``` +```python +""" Export all photos to ~/Desktop/export + If file has been edited, export the edited version, + otherwise, export the original version """ + +import os.path + +import osxphotos + +def main(): + photosdb = osxphotos.PhotosDB() + photos = photosdb.photos() + + export_path = os.path.expanduser("~/Desktop/export") + + for p in photos: + if not p.ismissing(): + if p.hasadjustments(): + exported = p.export(export_path, edited=True) + else: + exported = p.export(export_path) + print(f"Exported {p.filename()} to {exported}") + else: + print(f"Skipping missing photo: {p.filename()}") + +if __name__ == "__main__": + main() +``` + ## Module Interface ### Utility Functions @@ -447,31 +476,6 @@ for p in photos: ) ``` -```python -""" Export all photos to ~/Desktop/export - If file has been edited, export the edited version, - otherwise, export the original version """ - -import os.path - -import osxphotos - -photosdb = osxphotos.PhotosDB() -photos = photosdb.photos() - -export_path = os.path.expanduser("~/Desktop/export") - -for p in photos: - if not p.ismissing(): - if p.hasadjustments(): - exported = p.export(export_path, edited=True) - else: - exported = p.export(export_path) - print(f"Exported {p.filename()} to {exported}") - else: - print(f"Skipping missing photo: {p.filename()}") -``` - ## History This project started as a command line utility, `photosmeta`, available at [photosmeta](https://github.com/RhetTbull/photosmeta) This module converts the photosmeta Photos library query functionality into a module. diff --git a/examples/export.py b/examples/export.py index e93c2569..4eed0866 100644 --- a/examples/export.py +++ b/examples/export.py @@ -6,17 +6,21 @@ import os.path import osxphotos -photosdb = osxphotos.PhotosDB() -photos = photosdb.photos() +def main(): + photosdb = osxphotos.PhotosDB() + photos = photosdb.photos() -export_path = os.path.expanduser("~/Desktop/export") + export_path = os.path.expanduser("~/Desktop/export") -for p in photos: - if not p.ismissing(): - if p.hasadjustments(): - exported = p.export(export_path, edited=True) + for p in photos: + if not p.ismissing(): + if p.hasadjustments(): + exported = p.export(export_path, edited=True) + else: + exported = p.export(export_path) + print(f"Exported {p.filename()} to {exported}") else: - exported = p.export(export_path) - print(f"Exported {p.filename()} to {exported}") - else: - print(f"Skipping missing photo: {p.filename()}") + print(f"Skipping missing photo: {p.filename()}") + +if __name__ == "__main__": + main() \ No newline at end of file