mirror of
https://github.com/ihabunek/toot.git
synced 2024-09-15 04:18:05 -04:00
wip
This commit is contained in:
parent
4f508bd26a
commit
1c9aad68b6
@ -74,3 +74,11 @@ def logger_trace_config() -> TraceConfig:
|
|||||||
|
|
||||||
async def verify_credentials(session: ClientSession) -> ClientResponse:
|
async def verify_credentials(session: ClientSession) -> ClientResponse:
|
||||||
return await session.get("/api/v1/accounts/verify_credentials")
|
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}")
|
||||||
|
@ -138,6 +138,11 @@ def pass_session(f: "t.Callable[te.Concatenate[aiohttp.ClientSession, P], t.Awai
|
|||||||
session = await make_session(context)
|
session = await make_session(context)
|
||||||
try:
|
try:
|
||||||
return await f(session, *args, **kwargs)
|
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:
|
finally:
|
||||||
await session.close()
|
await session.close()
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ from toot.cli import InstanceParamType, async_command, cli, get_context, json_op
|
|||||||
async def whoami(session: ClientSession, json: bool):
|
async def whoami(session: ClientSession, json: bool):
|
||||||
"""Display logged in user details"""
|
"""Display logged in user details"""
|
||||||
response = await ahttp.verify_credentials(session)
|
response = await ahttp.verify_credentials(session)
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
if json:
|
if json:
|
||||||
click.echo(await response.text())
|
click.echo(await response.text())
|
||||||
@ -31,10 +32,11 @@ async def whoami(session: ClientSession, json: bool):
|
|||||||
@cli.command()
|
@cli.command()
|
||||||
@click.argument("account")
|
@click.argument("account")
|
||||||
@json_option
|
@json_option
|
||||||
@pass_context
|
@async_command
|
||||||
def whois(ctx: Context, account: str, json: bool):
|
@pass_session
|
||||||
|
async def whois(session: ClientSession, account: str, json: bool):
|
||||||
"""Display account details"""
|
"""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.
|
# Here it's not possible to avoid parsing json since it's needed to find the account.
|
||||||
if json:
|
if json:
|
||||||
@ -91,14 +93,17 @@ def search(ctx: Context, query: str, resolve: bool, json: bool):
|
|||||||
@cli.command()
|
@cli.command()
|
||||||
@click.argument("status_id")
|
@click.argument("status_id")
|
||||||
@json_option
|
@json_option
|
||||||
@pass_context
|
@async_command
|
||||||
def status(ctx: Context, status_id: str, json: bool):
|
@pass_session
|
||||||
|
async def status(session: ClientSession, status_id: str, json: bool):
|
||||||
"""Show a single status"""
|
"""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:
|
if json:
|
||||||
click.echo(response.text)
|
click.echo(await response.text())
|
||||||
else:
|
else:
|
||||||
status = from_dict(Status, response.json())
|
status = from_dict(Status, await response.json())
|
||||||
print_status(status)
|
print_status(status)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user