mirror of
https://github.com/ihabunek/toot.git
synced 2024-09-29 04:35:54 -04:00
Implement following/followers list retrieval
This commit is contained in:
parent
44a30b44d8
commit
e171578878
16
toot/api.py
16
toot/api.py
@ -260,6 +260,22 @@ def follow(app, user, account):
|
|||||||
def unfollow(app, user, account):
|
def unfollow(app, user, account):
|
||||||
return _account_action(app, user, account, 'unfollow')
|
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):
|
def mute(app, user, account):
|
||||||
return _account_action(app, user, account, 'mute')
|
return _account_action(app, user, account, 'mute')
|
||||||
|
@ -5,7 +5,7 @@ import sys
|
|||||||
from toot import api, config
|
from toot import api, config
|
||||||
from toot.auth import login_interactive, login_browser_interactive, create_app_interactive
|
from toot.auth import login_interactive, login_browser_interactive, create_app_interactive
|
||||||
from toot.exceptions import ConsoleError, NotFoundError
|
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)
|
print_search_results, print_timeline, print_notifications)
|
||||||
from toot.utils import assert_domain_exists, editor_input, multiline_input, EOF_KEY
|
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'])
|
api.unfollow(app, user, account['id'])
|
||||||
print_out("<green>✓ You are no longer following {}</green>".format(args.account))
|
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):
|
def mute(app, user, args):
|
||||||
account = _find_account(app, user, args.account)
|
account = _find_account(app, user, args.account)
|
||||||
|
@ -441,6 +441,22 @@ ACCOUNTS_COMMANDS = [
|
|||||||
],
|
],
|
||||||
require_auth=True,
|
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(
|
Command(
|
||||||
name="mute",
|
name="mute",
|
||||||
description="Mute an account",
|
description="Mute an account",
|
||||||
|
@ -126,6 +126,12 @@ HASHTAG_PATTERN = re.compile(r'(?<!\w)(#\w+)\b')
|
|||||||
def highlight_hashtags(line):
|
def highlight_hashtags(line):
|
||||||
return re.sub(HASHTAG_PATTERN, '<cyan>\\1</cyan>', 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):
|
def print_search_results(results):
|
||||||
accounts = results['accounts']
|
accounts = results['accounts']
|
||||||
@ -133,11 +139,7 @@ def print_search_results(results):
|
|||||||
|
|
||||||
if accounts:
|
if accounts:
|
||||||
print_out("\nAccounts:")
|
print_out("\nAccounts:")
|
||||||
for account in accounts:
|
print_acct_list(accounts)
|
||||||
print_out("* <green>@{}</green> {}".format(
|
|
||||||
account['acct'],
|
|
||||||
account['display_name']
|
|
||||||
))
|
|
||||||
|
|
||||||
if hashtags:
|
if hashtags:
|
||||||
print_out("\nHashtags:")
|
print_out("\nHashtags:")
|
||||||
|
Loading…
Reference in New Issue
Block a user