From 2e0f2548e609b776a9c39bf1ef5d9c9197e8c1d8 Mon Sep 17 00:00:00 2001 From: Dan Schwarz Date: Sun, 19 Mar 2023 20:27:20 -0400 Subject: [PATCH] Added toot list_remove_account command --- toot/api.py | 2 +- toot/commands.py | 16 ++++++++++++++++ toot/console.py | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/toot/api.py b/toot/api.py index 3d9e956..8557c74 100644 --- a/toot/api.py +++ b/toot/api.py @@ -559,5 +559,5 @@ def add_accounts_to_list(app, user, list_id, account_ids): def remove_accounts_from_list(app, user, list_id, account_ids): url = f"/api/v1/lists/{list_id}/accounts" - json = {'account_ids[]': account_ids} + json = {'account_ids': account_ids} return http.delete(app, user, url, json=json) diff --git a/toot/commands.py b/toot/commands.py index 4a7c908..7120f2f 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -462,6 +462,22 @@ def list_add_account(app, user, args): print_out(f"{ex}") +def list_remove_account(app, user, args): + list_id = args.id if args.id else api.find_list_id(app, user, args.title) + if not list_id: + print_out("List not found") + return + account = find_account(app, user, args.account) + if not account: + print_out("Account not found") + return + try: + api.remove_accounts_from_list(app, user, list_id, [account['id']]) + print_out(f"✓ Removed account \"{args.account}\"") + except Exception as ex: + print_out(f"{ex}") + + 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 cfe20ff..5583fe0 100644 --- a/toot/console.py +++ b/toot/console.py @@ -798,6 +798,25 @@ LIST_COMMANDS = [ ], require_auth=True, ), + Command( + name="list_remove_account", + description="Remove account from list", + arguments=[ + (["--id"], { + "type": str, + "help": "ID of the list" + }), + (["--title"], { + "type": str, + "help": "title of the list" + }), + (["--account"], { + "type": str, + "help": "Account to remove" + }), + ], + require_auth=True, + ), ] COMMAND_GROUPS = [ ("Authentication", AUTH_COMMANDS),