diff --git a/cry/cli.py b/cry/cli.py index 499f664..7d8ea51 100644 --- a/cry/cli.py +++ b/cry/cli.py @@ -120,11 +120,16 @@ def refresh(url): @cli.command(name="show") -def show(): - """Show feeds.""" +@click.argument("pattern", required=False, default="") +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() - feeds = db.load_all() + feeds = db.load_all(pattern=pattern or "") def feed_sort_key(f: feed.Feed) -> int: if len(f.entries) > 0: diff --git a/cry/database.py b/cry/database.py index 1bb303c..0a970cf 100644 --- a/cry/database.py +++ b/cry/database.py @@ -153,7 +153,9 @@ class Database: 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( """ SELECT @@ -166,7 +168,10 @@ class Database: title, link FROM feeds - """ + WHERE title LIKE :sql_pattern ESCAPE '\\' + OR link LIKE :sql_pattern ESCAPE '\\' + """, + {"sql_pattern": sql_pattern}, ) rows = cursor.fetchall()