Ivan Habunek 2024-04-30 12:25:01 +02:00
rodzic 4f508bd26a
commit 1c9aad68b6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: F5F0623FF5EBCB3D
3 zmienionych plików z 26 dodań i 8 usunięć

Wyświetl plik

@ -74,3 +74,11 @@ def logger_trace_config() -> TraceConfig:
async def verify_credentials(session: ClientSession) -> ClientResponse:
return await session.get("/api/v1/accounts/verify_credentials")
async def fetch_status(session: ClientSession, status_id: str) -> ClientResponse:
"""
Fetch a single status
https://docs.joinmastodon.org/methods/statuses/#get
"""
return await session.get(f"/api/v1/statuses/{status_id}")

Wyświetl plik

@ -138,6 +138,11 @@ def pass_session(f: "t.Callable[te.Concatenate[aiohttp.ClientSession, P], t.Awai
session = await make_session(context)
try:
return await f(session, *args, **kwargs)
except aiohttp.ClientResponseError as ex:
print(type(ex))
from pprint import pp
pp(ex.__dict__)
raise click.ClickException("foo")
finally:
await session.close()

Wyświetl plik

@ -20,6 +20,7 @@ from toot.cli import InstanceParamType, async_command, cli, get_context, json_op
async def whoami(session: ClientSession, json: bool):
"""Display logged in user details"""
response = await ahttp.verify_credentials(session)
response.raise_for_status()
if json:
click.echo(await response.text())
@ -31,10 +32,11 @@ async def whoami(session: ClientSession, json: bool):
@cli.command()
@click.argument("account")
@json_option
@pass_context
def whois(ctx: Context, account: str, json: bool):
@async_command
@pass_session
async def whois(session: ClientSession, account: str, json: bool):
"""Display account details"""
account_dict = api.find_account(ctx.app, ctx.user, account)
account_dict = ahttp.find_account(ctx.app, ctx.user, account)
# Here it's not possible to avoid parsing json since it's needed to find the account.
if json:
@ -91,14 +93,17 @@ def search(ctx: Context, query: str, resolve: bool, json: bool):
@cli.command()
@click.argument("status_id")
@json_option
@pass_context
def status(ctx: Context, status_id: str, json: bool):
@async_command
@pass_session
async def status(session: ClientSession, status_id: str, json: bool):
"""Show a single status"""
response = api.fetch_status(ctx.app, ctx.user, status_id)
response = await ahttp.fetch_status(session, status_id)
response.raise_for_status()
if json:
click.echo(response.text)
click.echo(await response.text())
else:
status = from_dict(Status, response.json())
status = from_dict(Status, await response.json())
print_status(status)