Add option to specify cache sort
from plex_trakt_sync.path import trakt_cache
-def get_sorted_cache(session: CachedSession):
- sorter = partial(sorted, reverse=True, key=lambda x: len(x[1].content))
+def get_sorted_cache(session: CachedSession, sorting: str):
+ sorters = {
+ "size": partial(sorted, reverse=True, key=lambda x: len(x[1].content)),
+ "date": partial(sorted, reverse=True, key=lambda x: x[1].created_at),
+ }
+ sorter = sorters[sorting]
yield from sorter(session.cache._get_valid_responses())
@click.command()
-def cache():
+@click.option(
+ "--sort",
+ type=click.Choice(["size", "date"], case_sensitive=False),
+ default="size",
+ show_default=True, help="Sort mode"
+)
+def cache(sort: str):
"""
Manage and analyze Requests Cache.
"""
@@ -20,5 +30,5 @@ def cache():
click.echo(f"Cache status:\n{session.cache}\n")
click.echo(f"URLs:")
- for k, r in get_sorted_cache(session):
+ for k, r in get_sorted_cache(session, sort):
click.echo(f"- {r.created_at}: {r.url}: {len(r.content)} bytes")
