Count, show in the right order
This commit is contained in:
parent
34c0b6dd7d
commit
c06f3ef114
1 changed files with 11 additions and 3 deletions
14
cry/cli.py
14
cry/cli.py
|
|
@ -121,7 +121,15 @@ def refresh(url):
|
||||||
|
|
||||||
@cli.command(name="show")
|
@cli.command(name="show")
|
||||||
@click.argument("pattern", required=False, default="")
|
@click.argument("pattern", required=False, default="")
|
||||||
def show(pattern):
|
@click.option(
|
||||||
|
"--count",
|
||||||
|
"-c",
|
||||||
|
type=int,
|
||||||
|
default=10,
|
||||||
|
show_default=True,
|
||||||
|
help="Show at most this many entries from each feed.",
|
||||||
|
)
|
||||||
|
def show(pattern, count):
|
||||||
"""Show feeds and entries.
|
"""Show feeds and entries.
|
||||||
|
|
||||||
If a pattern is supplied, then filter the feeds to urls or titles that
|
If a pattern is supplied, then filter the feeds to urls or titles that
|
||||||
|
|
@ -129,14 +137,14 @@ def show(pattern):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
db = database.Database.local()
|
db = database.Database.local()
|
||||||
feeds = db.load_all(pattern=pattern or "")
|
feeds = db.load_all(feed_limit=count, pattern=pattern or "")
|
||||||
|
|
||||||
def feed_sort_key(f: feed.Feed) -> int:
|
def feed_sort_key(f: feed.Feed) -> int:
|
||||||
if len(f.entries) > 0:
|
if len(f.entries) > 0:
|
||||||
return max(e.inserted_at for e in f.entries)
|
return max(e.inserted_at for e in f.entries)
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
feeds.sort(key=feed_sort_key)
|
feeds.sort(key=feed_sort_key, reverse=True)
|
||||||
for f in feeds:
|
for f in feeds:
|
||||||
click.echo(f"{f.title}")
|
click.echo(f"{f.title}")
|
||||||
if len(f.entries) > 0:
|
if len(f.entries) > 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue