From 08bb7aae71e3945c9d68d0797486ee896dcc2d59 Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Tue, 14 Mar 2023 19:14:58 -0400 Subject: [PATCH] added "toot list_accounts" command --- toot/api.py | 16 ++++++++++++++++ toot/commands.py | 7 ++++++- toot/console.py | 12 ++++++++++++ toot/output.py | 8 ++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/toot/api.py b/toot/api.py index 7752af4..d0edb88 100644 --- a/toot/api.py +++ b/toot/api.py @@ -524,3 +524,19 @@ def get_instance(base_url): def get_lists(app, user): path = "/api/v1/lists" return _get_response_list(app, user, path) + + +def find_list_id(app, user, title): + lists = get_lists(app, user) + for list_item in lists: + if list_item["title"] == title: + return list_item["id"] + return None + + +def get_list_accounts(app, user, title): + id = find_list_id(app, user, title) + if id: + path = "/api/v1/{id}/accounts" + return _get_response_list(app, user, path) + return [] diff --git a/toot/commands.py b/toot/commands.py index 1e45dc4..cc513ed 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -9,7 +9,7 @@ from toot.auth import login_interactive, login_browser_interactive, create_app_i from toot.exceptions import ApiError, ConsoleError from toot.output import (print_out, print_instance, print_account, print_acct_list, print_search_results, print_timeline, print_notifications, - print_tag_list, print_list_list) + print_tag_list, print_list_list, print_list_accounts) from toot.tui.utils import parse_datetime from toot.utils import args_get_instance, delete_tmp_status_file, editor_input, multiline_input, EOF_KEY @@ -429,6 +429,11 @@ def lists(app, user, args): print_list_list(response) +def list_accounts(app, user, args): + response = api.get_list_accounts(app, user, args.title) + print_list_accounts(args.title[0], response) + + def mute(app, user, args): account = find_account(app, user, args.account) api.mute(app, user, account['id']) diff --git a/toot/console.py b/toot/console.py index bd26148..146e5b6 100644 --- a/toot/console.py +++ b/toot/console.py @@ -731,6 +731,18 @@ LIST_COMMANDS = [ arguments=[], require_auth=True, ), + Command( + name="list_accounts", + description="List the accounts in a list", + arguments=[ + (["--title"], { + "action": "append", + "type": str, + "help": "title of the list" + }), + ], + require_auth=True, + ), ] COMMAND_GROUPS = [ ("Authentication", AUTH_COMMANDS), diff --git a/toot/output.py b/toot/output.py index ba8c54e..1114748 100644 --- a/toot/output.py +++ b/toot/output.py @@ -221,6 +221,14 @@ def print_list_list(lists): print_out("You have no lists defined.") +def print_list_accounts(list_title, accounts): + print_out(f"Accounts in list \"{list_title}\":\n") + if accounts: + print_acct_list(accounts) + else: + print_out("This list has no accounts.") + + def print_search_results(results): accounts = results['accounts'] hashtags = results['hashtags']