Implemented --query-function, #430

This commit is contained in:
Rhet Turnbull
2021-06-20 17:26:07 -07:00
parent be363b9727
commit 07da8031c6
6 changed files with 109 additions and 6 deletions

View File

@@ -1,6 +1,5 @@
""" example function for osxphotos --query-function """
from typing import List
from osxphotos import PhotoInfo
@@ -13,9 +12,20 @@ def best_selfies(photos: List[PhotoInfo]) -> List[PhotoInfo]:
# get list of selfies sorted by date
photos = sorted([p for p in photos if p.selfie], key=lambda p: p.date)
if not photos:
return []
start_year = photos[0].date.year
stop_year = photos[-1].date.year
print(start_year, stop_year)
best_selfies = []
for year in range(start_year, stop_year + 1):
# find best selfie each year as determined by overall aesthetic score
selfies = sorted(
[p for p in photos if p.date.year == year],
key=lambda p: p.score.overall,
reverse=True,
)
if selfies:
best_selfies.append(selfies[0])
return photos
return best_selfies