Skip to content

Commit

Permalink
Implement following/followers list retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
Oblomov authored and ihabunek committed Nov 18, 2022
1 parent 44a30b4 commit e171578
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
16 changes: 16 additions & 0 deletions toot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
12 changes: 11 additions & 1 deletion toot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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

Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions toot/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,22 @@ def editor(value):
],
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",
Expand Down
12 changes: 7 additions & 5 deletions toot/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,20 @@ def print_account(account):
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']
hashtags = results['hashtags']

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:")
Expand Down

0 comments on commit e171578

Please sign in to comment.