mirror of
https://github.com/ihabunek/toot
synced 2025-02-15 19:40:42 +01:00
Migrate thread command
This commit is contained in:
parent
dc376f67d8
commit
88bd6df85b
10
toot/aapi.py
10
toot/aapi.py
@ -116,3 +116,13 @@ async def post_status(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return await request(ctx, "POST", "/api/v1/statuses", json=data, headers=headers)
|
return await request(ctx, "POST", "/api/v1/statuses", json=data, headers=headers)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_status(ctx: Context, status_id) -> Response:
|
||||||
|
url = f"/api/v1/statuses/{status_id}"
|
||||||
|
return await request(ctx, "GET", url)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_status_context(ctx: Context, status_id) -> Response:
|
||||||
|
url = f"/api/v1/statuses/{status_id}/context"
|
||||||
|
return await request(ctx, "GET", url)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
import asyncio
|
||||||
import sys
|
import sys
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
@ -68,16 +69,24 @@ def timeline(app, user, args, generator=None):
|
|||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def thread(app, user, args):
|
async def thread(ctx: Context, args):
|
||||||
toot = api.single_status(app, user, args.status_id)
|
if args.json:
|
||||||
context = api.context(app, user, args.status_id)
|
context_response = await aapi.get_status_context(ctx, args.status_id)
|
||||||
|
print_out(context_response.body)
|
||||||
|
else:
|
||||||
|
status_response, context_response = await asyncio.gather(
|
||||||
|
aapi.get_status(ctx, args.status_id),
|
||||||
|
aapi.get_status_context(ctx, args.status_id),
|
||||||
|
)
|
||||||
|
status = status_response.json
|
||||||
|
context = context_response.json
|
||||||
thread = []
|
thread = []
|
||||||
for item in context['ancestors']:
|
for item in context["ancestors"]:
|
||||||
thread.append(item)
|
thread.append(item)
|
||||||
|
|
||||||
thread.append(toot)
|
thread.append(status)
|
||||||
|
|
||||||
for item in context['descendants']:
|
for item in context["descendants"]:
|
||||||
thread.append(item)
|
thread.append(item)
|
||||||
|
|
||||||
statuses = [from_dict(Status, s) for s in thread]
|
statuses = [from_dict(Status, s) for s in thread]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user