Implement following/followers list retrieval

This commit is contained in:
Giuseppe Bilotta 2022-11-17 22:45:51 +01:00 committed by Ivan Habunek
parent 44a30b44d8
commit e171578878
4 changed files with 50 additions and 6 deletions

View File

@ -260,6 +260,22 @@ def follow(app, user, account):
def unfollow(app, user, account):
return _account_action(app, user, account, 'unfollow')
def _get_account_list(app, user, path):
accounts = []
while path:
response = http.get(app, user, path)
accounts += response.json()
path = _get_next_path(response.headers)
return accounts
def following(app, user, account):
path = '/api/v1/accounts/{}/{}'.format(account, 'following')
return _get_account_list(app, user, path)
def followers(app, user, account):
path = '/api/v1/accounts/{}/{}'.format(account, 'followers')
return _get_account_list(app, user, path)
def mute(app, user, account):
return _account_action(app, user, account, 'mute')

View File

@ -5,7 +5,7 @@ import sys
from toot import api, config
from toot.auth import login_interactive, login_browser_interactive, create_app_interactive
from toot.exceptions import ConsoleError, NotFoundError
from toot.output import (print_out, print_instance, print_account,
from toot.output import (print_out, print_instance, print_account, print_acct_list,
print_search_results, print_timeline, print_notifications)
from toot.utils import assert_domain_exists, editor_input, multiline_input, EOF_KEY
@ -279,6 +279,16 @@ def unfollow(app, user, args):
api.unfollow(app, user, account['id'])
print_out("<green>✓ You are no longer following {}</green>".format(args.account))
def following(app, user, args):
account = _find_account(app, user, args.account)
response = api.following(app, user, account['id'])
print_acct_list(response)
def followers(app, user, args):
account = _find_account(app, user, args.account)
response = api.followers(app, user, account['id'])
print_acct_list(response)
def mute(app, user, args):
account = _find_account(app, user, args.account)

View File

@ -441,6 +441,22 @@ ACCOUNTS_COMMANDS = [
],
require_auth=True,
),
Command(
name="following",
description="List accounts followed by the given account",
arguments=[
account_arg,
],
require_auth=True,
),
Command(
name="followers",
description="List accounts following the given account",
arguments=[
account_arg,
],
require_auth=True,
),
Command(
name="mute",
description="Mute an account",

View File

@ -126,6 +126,12 @@ HASHTAG_PATTERN = re.compile(r'(?<!\w)(#\w+)\b')
def highlight_hashtags(line):
return re.sub(HASHTAG_PATTERN, '<cyan>\\1</cyan>', line)
def print_acct_list(accounts):
for account in accounts:
print_out("* <green>@{}</green> {}".format(
account['acct'],
account['display_name']
))
def print_search_results(results):
accounts = results['accounts']
@ -133,11 +139,7 @@ def print_search_results(results):
if accounts:
print_out("\nAccounts:")
for account in accounts:
print_out("* <green>@{}</green> {}".format(
account['acct'],
account['display_name']
))
print_acct_list(accounts)
if hashtags:
print_out("\nHashtags:")