kopia lustrzana https://github.com/ihabunek/toot
				
				
				
			Migrate thread command
							rodzic
							
								
									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) | ||||
| 
 | ||||
| 
 | ||||
| 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 platform | ||||
| 
 | ||||
|  | @ -68,16 +69,24 @@ def timeline(app, user, args, generator=None): | |||
|             break | ||||
| 
 | ||||
| 
 | ||||
| def thread(app, user, args): | ||||
|     toot = api.single_status(app, user, args.status_id) | ||||
|     context = api.context(app, user, args.status_id) | ||||
| async def thread(ctx: Context, args): | ||||
|     if args.json: | ||||
|         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 = [] | ||||
|     for item in context['ancestors']: | ||||
|         for item in context["ancestors"]: | ||||
|             thread.append(item) | ||||
| 
 | ||||
|     thread.append(toot) | ||||
|         thread.append(status) | ||||
| 
 | ||||
|     for item in context['descendants']: | ||||
|         for item in context["descendants"]: | ||||
|             thread.append(item) | ||||
| 
 | ||||
|         statuses = [from_dict(Status, s) for s in thread] | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Ivan Habunek
						Ivan Habunek