Added --year query option, #593 (#670)

This commit is contained in:
Rhet Turnbull
2022-04-20 07:27:03 -06:00
committed by GitHub
parent 7e4977e2c5
commit 77433b01ed
10 changed files with 128 additions and 2 deletions

View File

@@ -368,6 +368,13 @@ def QUERY_OPTIONS(f):
help="Search by item end time of day, e.g. 12:00 or 12:00:00.",
type=TimeISO8601(),
),
o(
"--year",
help="Search for items from a specific year, e.g. --year 2022 to find all photos from the year 2022. "
"May be repeated to search multiple years.",
multiple=True,
type=int,
),
o("--has-comment", is_flag=True, help="Search for photos that have comments."),
o("--no-comment", is_flag=True, help="Search for photos with no comments."),
o("--has-likes", is_flag=True, help="Search for photos that have likes."),

View File

@@ -697,6 +697,7 @@ def export(
to_date,
from_time,
to_time,
year,
verbose,
timestamp,
no_progress,
@@ -1018,6 +1019,7 @@ def export(
uuid_from_file = cfg.uuid_from_file
verbose = cfg.verbose
xattr_template = cfg.xattr_template
year = cfg.year
# config file might have changed verbose
color_theme = get_theme(theme)
@@ -1300,6 +1302,7 @@ def export(
to_date=to_date,
from_time=from_time,
to_time=to_time,
year=year,
portrait=portrait,
not_portrait=not_portrait,
screenshot=screenshot,

View File

@@ -111,6 +111,7 @@ def query(
to_date,
from_time,
to_time,
year,
portrait,
not_portrait,
screenshot,
@@ -174,6 +175,7 @@ def query(
to_date,
from_time,
to_time,
year,
label,
is_reference,
query_eval,
@@ -280,6 +282,7 @@ def query(
to_date=to_date,
from_time=from_time,
to_time=to_time,
year=year,
portrait=portrait,
not_portrait=not_portrait,
screenshot=screenshot,

View File

@@ -256,6 +256,7 @@ def _query_options_from_kwargs(**kwargs) -> QueryOptions:
"to_date",
"from_time",
"to_time",
"year",
"label",
"is_reference",
"query_eval",

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>osxphotos.photosdb.photosdb &#8212; osxphotos 0.47.5 documentation</title>
<title>osxphotos.photosdb.photosdb &#8212; osxphotos 0.47.8 documentation</title>
<link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../../../_static/alabaster.css" />
<script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
@@ -3322,6 +3322,9 @@
<span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">to_time</span><span class="p">:</span>
<span class="n">photos</span> <span class="o">=</span> <span class="p">[</span><span class="n">p</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">photos</span> <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">&lt;=</span> <span class="n">options</span><span class="o">.</span><span class="n">to_time</span><span class="p">]</span>
<span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">year</span><span class="p">:</span>
<span class="n">photos</span> <span class="o">=</span> <span class="p">[</span><span class="n">p</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">photos</span> <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">year</span> <span class="ow">in</span> <span class="n">options</span><span class="o">.</span><span class="n">year</span><span class="p">]</span>
<span class="k">if</span> <span class="n">name</span><span class="p">:</span>
<span class="c1"># search filename fields for text</span>
<span class="c1"># if more than one, find photos with all title values in filename</span>

View File

@@ -3289,6 +3289,9 @@ class PhotosDB:
if options.to_time:
photos = [p for p in photos if p.date.time() <= options.to_time]
if options.year:
photos = [p for p in photos if p.date.year in options.year]
if name:
# search filename fields for text
# if more than one, find photos with all title values in filename

View File

@@ -87,6 +87,7 @@ class QueryOptions:
function: Optional[List[Tuple[callable, str]]] = None
selected: Optional[bool] = None
exif: Optional[Iterable[Tuple[str, str]]] = None
year: Optional[int] = None
def asdict(self):
return asdict(self)