From be363b9727d6fca6e747b0d952cd3252ddfe6e3b Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sun, 20 Jun 2021 16:38:51 -0700 Subject: [PATCH] Added query function [skip ci] --- examples/query_function.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/query_function.py diff --git a/examples/query_function.py b/examples/query_function.py new file mode 100644 index 00000000..61aa76a4 --- /dev/null +++ b/examples/query_function.py @@ -0,0 +1,21 @@ +""" example function for osxphotos --query-function """ + + +from typing import List + +from osxphotos import PhotoInfo + + +# call this with --query-function:examples/query_function.py::best_selfies +def best_selfies(photos: List[PhotoInfo]) -> List[PhotoInfo]: + """your query function should take a list of PhotoInfo objects and return a list of PhotoInfo objects (or empty list)""" + # this example finds your best selfie for every year + + # get list of selfies sorted by date + photos = sorted([p for p in photos if p.selfie], key=lambda p: p.date) + + start_year = photos[0].date.year + stop_year = photos[-1].date.year + print(start_year, stop_year) + + return photos \ No newline at end of file