Implement --reverse option
MODIFY
plex_trakt_sync/commands/cache.py
plex_trakt_sync/commands/cache.py
from plex_trakt_sync.path import trakt_cache
-def get_sorted_cache(session: CachedSession, sorting: str):
+def get_sorted_cache(session: CachedSession, sorting: str, reverse: bool):
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),
+ "size": partial(sorted, reverse=reverse, key=lambda x: len(x[1].content)),
+ "date": partial(sorted, reverse=reverse, key=lambda x: x[1].created_at),
}
sorter = sorters[sorting]
yield from sorter(session.cache._get_valid_responses())
@@ -40,7 +40,13 @@ def limit_iterator(items, limit: int):
default=20,
show_default=True, help="Limit entries to be printed"
)
-def cache(sort: str, limit: int):
+@click.option(
+ "--reverse",
+ is_flag=True,
+ default=False,
+ help="Sort reverse"
+)
+def cache(sort: str, limit: int, reverse: bool):
"""
Manage and analyze Requests Cache.
"""
@@ -48,6 +54,6 @@ def cache(sort: str, limit: int):
click.echo(f"Cache status:\n{session.cache}\n")
click.echo(f"URLs:")
- sorted = get_sorted_cache(session, sort)
+ sorted = get_sorted_cache(session, sort, reverse)
for i, (k, r) in limit_iterator(sorted, limit):
click.echo(f"- {i + 1:3d}. {r.created_at}: {r.url}: {len(r.content)} bytes")

Implement --reverse option