From ce50b4f8939ad5fbf7fa40255320a399dd713513 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Tue, 24 Dec 2019 08:57:59 -0800 Subject: [PATCH] Fix to export logic for missing photos --- README.md | 7 +++++++ osxphotos/__main__.py | 24 +++++------------------- osxphotos/_version.py | 2 +- osxphotos/utils.py | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 5d9e5c8f..7c85261e 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ - [```get_last_library_path()```](#get_last_library_path) - [```list_photo_libraries()```](#list_photo_libraries) - [```dd_to_dms_str(lat, lon)```](#dd_to_dms_strlat-lon) + - [```create_path_by_date(dest, dt)```](#create_path_by_datedest-dt) + [Examples](#examples) * [Related Projects](#related-projects) * [Contributing](#contributing) @@ -56,6 +57,7 @@ * [Dependencies](#dependencies) * [Acknowledgements](#acknowledgements) + ## What is osxphotos? OSXPhotos provides the ability to interact with and query Apple's Photos.app library database on MacOS. Using this module you can query the Photos database for information about the photos stored in a Photos library on your Mac--for example, file name, file path, and metadata such as keywords/tags, persons/faces, albums, etc. You can also easily export both the original and edited photos. @@ -535,6 +537,11 @@ lon: longitude in degrees returns: string tuple in format ("51 deg 30' 12.86\\" N", "0 deg 7' 54.50\\" W") This is the same format used by exiftool's json format. +#### ```create_path_by_date(dest, dt)``` +Creates a path in dest folder in form dest/YYYY/MM/DD/ +dest: valid path as str +dt: datetime.timetuple() object +Checks to see if path exists, if it does, do nothing and return path. If path does not exist, creates it and returns path. Useful for exporting photos to a date-based folder structure. ### Examples diff --git a/osxphotos/__main__.py b/osxphotos/__main__.py index 9f699625..a2084f9f 100644 --- a/osxphotos/__main__.py +++ b/osxphotos/__main__.py @@ -13,6 +13,7 @@ import osxphotos from ._constants import _EXIF_TOOL_URL from ._version import __version__ +from .utils import create_path_by_date # TODO: add "--any" to search any field (e.g. keyword, description, title contains "wedding") (add case insensitive option) @@ -483,7 +484,10 @@ def export( export_edited, original_name, ) - click.echo(f"Exported {p.filename} to {export_path}") + if export_path: + click.echo(f"Exported {p.filename} to {export_path}") + else: + click.echo(f"Did not export missing file {p.filename}") else: click.echo("Did not find any photos to export") @@ -706,23 +710,5 @@ def export_photo( return photo_path -def create_path_by_date(dest, dt): - """ Creates a path in dest folder in form dest/YYYY/MM/DD/ - dest: valid path as str - dt: datetime.timetuple() object - Checks to see if path exists, if it does, do nothing and return path - If path does not exist, creates it and returns path""" - if not os.path.isdir(dest): - raise FileNotFoundError(f"dest {dest} must be valid path") - yyyy, mm, dd = dt[0:3] - yyyy = str(yyyy).zfill(4) - mm = str(mm).zfill(2) - dd = str(dd).zfill(2) - new_dest = os.path.join(dest, yyyy, mm, dd) - if not os.path.isdir(new_dest): - os.makedirs(new_dest) - return new_dest - - if __name__ == "__main__": cli() diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 99edb428..66c3302e 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.17.04" +__version__ = "0.17.06" diff --git a/osxphotos/utils.py b/osxphotos/utils.py index 225d01a5..6c8f6c4c 100644 --- a/osxphotos/utils.py +++ b/osxphotos/utils.py @@ -205,3 +205,21 @@ def list_photo_libraries(): lib_list = list(set(lib_list)) lib_list.sort() return lib_list + + +def create_path_by_date(dest, dt): + """ Creates a path in dest folder in form dest/YYYY/MM/DD/ + dest: valid path as str + dt: datetime.timetuple() object + Checks to see if path exists, if it does, do nothing and return path + If path does not exist, creates it and returns path""" + if not os.path.isdir(dest): + raise FileNotFoundError(f"dest {dest} must be valid path") + yyyy, mm, dd = dt[0:3] + yyyy = str(yyyy).zfill(4) + mm = str(mm).zfill(2) + dd = str(dd).zfill(2) + new_dest = os.path.join(dest, yyyy, mm, dd) + if not os.path.isdir(new_dest): + os.makedirs(new_dest) + return new_dest