allow year relative filtering

This commit is contained in:
ducklet 2021-06-22 09:59:48 +02:00
parent d09880438d
commit a6adfefdd8
3 changed files with 21 additions and 5 deletions

View file

@ -1,6 +1,7 @@
import base64
import binascii
import logging
from typing import Literal
from starlette.applications import Starlette
from starlette.authentication import (
@ -50,6 +51,18 @@ def truthy(s: str):
return bool(s) and s.lower() in {"1", "yes", "true"}
def yearcomp(s: str):
if not s:
return
comp: Literal["<", "=", ">"] = "="
if (prefix := s[0]) in "<=>":
comp = prefix # type: ignore
s = s[len(prefix) :]
return comp, int(s)
async def ratings(request):
params = request.query_params
rows = await find_ratings(
@ -57,7 +70,7 @@ async def ratings(request):
media_type=params.get("media_type"),
ignore_tv_episodes=truthy(params.get("ignore_tv_episodes")),
include_unrated=truthy(params.get("include_unrated")),
year=int(params["year"]) if "year" in params else None,
yearcomp=yearcomp(params["year"]) if "year" in params else None,
)
aggr = {}