diff --git a/README.md b/README.md index e19d0de7..1f15b1ed 100644 --- a/README.md +++ b/README.md @@ -449,11 +449,11 @@ photosdb.db_version Returns the version number for Photos library database. You likely won't need this but it's provided in case needed for debugging. PhotosDB will print a warning to `sys.stderr` if you open a database version that has not been tested. -#### ` photos(keywords=None, uuid=None, persons=None, albums=None, images=True, movies=False)` +#### ` photos(keywords=None, uuid=None, persons=None, albums=None, images=True, movies=False, from_date=None, to_date=None)` ```python # assumes photosdb is a PhotosDB object (see above) -photos = photosdb.photos([keywords=['keyword',]], [uuid=['uuid',]], [persons=['person',]], [albums=['album',]]) +photos = photosdb.photos([keywords=['keyword',]], [uuid=['uuid',]], [persons=['person',]], [albums=['album',]],[from_date=datetime.datetime],[to_date=datetime.datetime]) ``` Returns a list of [PhotoInfo](#PhotoInfo) objects. Each PhotoInfo object represents a photo in the Photos Libary. @@ -469,6 +469,8 @@ photos = photosdb.photos( albums = [], images = bool, movies = bool, + from_date = datetime.datetime, + to_date = datetime.datetime ) ``` @@ -478,8 +480,10 @@ photos = photosdb.photos( - ```albums```: list of one or more album names. Returns only photos contained in the album(s). If more than one album name is provided, returns photos contained in any of the albums (.e.g. treated as "or") - ```images```: bool; if True, returns photos/images; default is True - ```movies```: bool; if True, returns movies/videos; default is False +- ```from_date```: datetime.datetime; if provided, finds photos where creation date >= from_date; default is None +- ```to_date```: datetime.datetime; if provided, finds photos where creation date <= to_date; default is None -If more than one of (keywords, uuid, persons, albums) is provided, they are treated as "and" criteria. E.g. +If more than one of (keywords, uuid, persons, albums,from_date, to_date) is provided, they are treated as "and" criteria. E.g. Finds all photos with (keyword = "wedding" or "birthday") and (persons = "Juan Rodriguez") diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 7ff27590..e9d5bf0f 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.22.3" +__version__ = "0.22.4" diff --git a/osxphotos/photosdb.py b/osxphotos/photosdb.py index 2262b7df..7020c68b 100644 --- a/osxphotos/photosdb.py +++ b/osxphotos/photosdb.py @@ -1328,6 +1328,8 @@ class PhotosDB: If more than one arg, returns photos matching all the criteria (e.g. keywords AND persons) images: if True, returns image files, if False, does not return images; default is True movies: if True, returns movie files, if False, does not return movies; default is False + from_date: return photos with creation date >= from_date (datetime.datetime object, default None) + to_date: return photos with creation date <= to_date (datetime.datetime object, default None) """ photos_sets = [] # list of photo sets to perform intersection of if not any([keywords, uuid, persons, albums, from_date, to_date]): diff --git a/osxphotos/utils.py b/osxphotos/utils.py index ef39f44b..e73ac5f6 100644 --- a/osxphotos/utils.py +++ b/osxphotos/utils.py @@ -289,6 +289,24 @@ def create_path_by_date(dest, dt): return new_dest +# TODO: this doesn't always work, still looking for a way to +# force Photos to open the library being operated on +# def _open_photos_library_applescript(library_path): +# """ Force Photos to open a specific library +# library_path: path to the Photos library """ +# open_scpt = AppleScript( +# f""" +# on openLibrary +# tell application "Photos" +# activate +# open POSIX file "{library_path}" +# end tell +# end openLibrary +# """ +# ) +# open_scpt.run() + + def _export_photo_uuid_applescript( uuid, dest, original=True, edited=False, timeout=120 ):