From 71d9c9ff12ac50c3ed1ef73db46e9d20f863438b Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Thu, 31 Oct 2024 17:19:54 +0100 Subject: [PATCH] search: add support for type, offset and limit from the command line --- toot/api.py | 6 ++++-- toot/cli/read.py | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/toot/api.py b/toot/api.py index 7bd2032..acdab02 100644 --- a/toot/api.py +++ b/toot/api.py @@ -549,7 +549,7 @@ def _add_mime_type(file): return (filename, file, mime_type) -def search(app, user, query, resolve=False, type=None): +def search(app, user, query, resolve=False, type=None, offset=None, limit=None): """ Perform a search. https://docs.joinmastodon.org/methods/search/#v2 @@ -557,7 +557,9 @@ def search(app, user, query, resolve=False, type=None): params = drop_empty_values({ "q": query, "resolve": str_bool(resolve), - "type": type + "type": type, + "offset": int(offset) if offset else None, + "limit": int(limit) if limit else None }) return http.get(app, user, "/api/v2/search", params) diff --git a/toot/cli/read.py b/toot/cli/read.py index 32ce49a..9209621 100644 --- a/toot/cli/read.py +++ b/toot/cli/read.py @@ -75,11 +75,16 @@ def instance(instance: Optional[str], json: bool): @cli.command() @click.argument("query") @click.option("-r", "--resolve", is_flag=True, help="Resolve non-local accounts") +@click.option("-t", "--type", help="Type of search (accounts, hashtags, statuses)") +@click.option("-o", "--offset", help="Return results starting from (default 0)") +@click.option("-l", "--limit", help="Maximum number of results (default 20, max 40)") @json_option @pass_context -def search(ctx: Context, query: str, resolve: bool, json: bool): +def search(ctx: Context, query: str, resolve: bool, + type: Optional[str], offset: Optional[int], limit: Optional[int], + json: bool): """Search for users or hashtags""" - response = api.search(ctx.app, ctx.user, query, resolve) + response = api.search(ctx.app, ctx.user, query, resolve, type, offset, limit) if json: click.echo(response.text) else: