mirror of
https://github.com/ihabunek/toot
synced 2024-12-23 15:37:47 +01:00
search: add support for type, offset and limit from the command line
This commit is contained in:
parent
89ea4604e5
commit
71d9c9ff12
@ -549,7 +549,7 @@ def _add_mime_type(file):
|
|||||||
return (filename, file, mime_type)
|
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.
|
Perform a search.
|
||||||
https://docs.joinmastodon.org/methods/search/#v2
|
https://docs.joinmastodon.org/methods/search/#v2
|
||||||
@ -557,7 +557,9 @@ def search(app, user, query, resolve=False, type=None):
|
|||||||
params = drop_empty_values({
|
params = drop_empty_values({
|
||||||
"q": query,
|
"q": query,
|
||||||
"resolve": str_bool(resolve),
|
"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)
|
return http.get(app, user, "/api/v2/search", params)
|
||||||
|
@ -75,11 +75,16 @@ def instance(instance: Optional[str], json: bool):
|
|||||||
@cli.command()
|
@cli.command()
|
||||||
@click.argument("query")
|
@click.argument("query")
|
||||||
@click.option("-r", "--resolve", is_flag=True, help="Resolve non-local accounts")
|
@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
|
@json_option
|
||||||
@pass_context
|
@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"""
|
"""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:
|
if json:
|
||||||
click.echo(response.text)
|
click.echo(response.text)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user