Filter show by pattern, if requested
This commit is contained in:
parent
26353a2779
commit
34c0b6dd7d
2 changed files with 15 additions and 5 deletions
11
cry/cli.py
11
cry/cli.py
|
|
@ -120,11 +120,16 @@ def refresh(url):
|
||||||
|
|
||||||
|
|
||||||
@cli.command(name="show")
|
@cli.command(name="show")
|
||||||
def show():
|
@click.argument("pattern", required=False, default="")
|
||||||
"""Show feeds."""
|
def show(pattern):
|
||||||
|
"""Show feeds and entries.
|
||||||
|
|
||||||
|
If a pattern is supplied, then filter the feeds to urls or titles that
|
||||||
|
match the pattern. Otherwise, just show everything.
|
||||||
|
"""
|
||||||
|
|
||||||
db = database.Database.local()
|
db = database.Database.local()
|
||||||
feeds = db.load_all()
|
feeds = db.load_all(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:
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,9 @@ class Database:
|
||||||
for url, last_fetched_ts, retry_after_ts, status, etag, modified in rows
|
for url, last_fetched_ts, retry_after_ts, status, etag, modified in rows
|
||||||
]
|
]
|
||||||
|
|
||||||
def load_all(self, feed_limit: int = 20) -> list[feed.Feed]:
|
def load_all(self, feed_limit: int = 20, pattern: str = "") -> list[feed.Feed]:
|
||||||
|
pattern = pattern.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_")
|
||||||
|
sql_pattern = f"%{pattern}%"
|
||||||
cursor = self.db.execute(
|
cursor = self.db.execute(
|
||||||
"""
|
"""
|
||||||
SELECT
|
SELECT
|
||||||
|
|
@ -166,7 +168,10 @@ class Database:
|
||||||
title,
|
title,
|
||||||
link
|
link
|
||||||
FROM feeds
|
FROM feeds
|
||||||
"""
|
WHERE title LIKE :sql_pattern ESCAPE '\\'
|
||||||
|
OR link LIKE :sql_pattern ESCAPE '\\'
|
||||||
|
""",
|
||||||
|
{"sql_pattern": sql_pattern},
|
||||||
)
|
)
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue