added "toot list_accounts" command
This commit is contained in:
parent
855b2a1526
commit
08bb7aae71
4 changed files with 42 additions and 1 deletions
16
toot/api.py
16
toot/api.py
|
@ -524,3 +524,19 @@ def get_instance(base_url):
|
||||||
def get_lists(app, user):
|
def get_lists(app, user):
|
||||||
path = "/api/v1/lists"
|
path = "/api/v1/lists"
|
||||||
return _get_response_list(app, user, path)
|
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 []
|
||||||
|
|
|
@ -9,7 +9,7 @@ from toot.auth import login_interactive, login_browser_interactive, create_app_i
|
||||||
from toot.exceptions import ApiError, ConsoleError
|
from toot.exceptions import ApiError, ConsoleError
|
||||||
from toot.output import (print_out, print_instance, print_account, print_acct_list,
|
from toot.output import (print_out, print_instance, print_account, print_acct_list,
|
||||||
print_search_results, print_timeline, print_notifications,
|
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.tui.utils import parse_datetime
|
||||||
from toot.utils import args_get_instance, delete_tmp_status_file, editor_input, multiline_input, EOF_KEY
|
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)
|
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):
|
def mute(app, user, args):
|
||||||
account = find_account(app, user, args.account)
|
account = find_account(app, user, args.account)
|
||||||
api.mute(app, user, account['id'])
|
api.mute(app, user, account['id'])
|
||||||
|
|
|
@ -731,6 +731,18 @@ LIST_COMMANDS = [
|
||||||
arguments=[],
|
arguments=[],
|
||||||
require_auth=True,
|
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 = [
|
COMMAND_GROUPS = [
|
||||||
("Authentication", AUTH_COMMANDS),
|
("Authentication", AUTH_COMMANDS),
|
||||||
|
|
|
@ -221,6 +221,14 @@ def print_list_list(lists):
|
||||||
print_out("You have no lists defined.")
|
print_out("You have no lists defined.")
|
||||||
|
|
||||||
|
|
||||||
|
def print_list_accounts(list_title, accounts):
|
||||||
|
print_out(f"Accounts in list <green>\"{list_title}\"</green>:\n")
|
||||||
|
if accounts:
|
||||||
|
print_acct_list(accounts)
|
||||||
|
else:
|
||||||
|
print_out("This list has no accounts.")
|
||||||
|
|
||||||
|
|
||||||
def print_search_results(results):
|
def print_search_results(results):
|
||||||
accounts = results['accounts']
|
accounts = results['accounts']
|
||||||
hashtags = results['hashtags']
|
hashtags = results['hashtags']
|
||||||
|
|
Loading…
Reference in a new issue