1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-11-03 04:17:21 -05:00

Add whois command

This commit is contained in:
Ivan Habunek 2017-04-19 15:29:40 +02:00
parent e1c993b9d0
commit 9b48432d04
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
2 changed files with 42 additions and 13 deletions

View File

@ -11,7 +11,7 @@ from datetime import datetime
from future.moves.itertools import zip_longest
from getpass import getpass
from itertools import chain
from textwrap import TextWrapper
from textwrap import TextWrapper, wrap
from toot import api, config, DEFAULT_INSTANCE, User, App, ConsoleError
from toot.output import green, yellow, print_error
@ -260,13 +260,34 @@ def _do_upload(app, user, file):
def _find_account(app, user, account_name):
"""For a given account name, returns the Account object or None if not found."""
"""For a given account name, returns the Account object or raises an exception if not found."""
response = api.search(app, user, account_name, False)
for account in response['accounts']:
if account['acct'] == account_name or "@" + account['acct'] == account_name:
return account
raise ConsoleError("Account not found")
def _print_account(account):
print("{} {}".format(green("@" + account['acct']), account['display_name']))
if account['note']:
print("")
note = BeautifulSoup(account['note'], "html.parser")
print("\n".join(wrap(note.get_text())))
print("")
print("ID: " + green(account['id']))
print("Since: " + green(account['created_at'][:19].replace('T', ' @ ')))
print("")
print("Followers: " + yellow(account['followers_count']))
print("Following: " + yellow(account['following_count']))
print("Statuses: " + yellow(account['statuses_count']))
print("")
print(account['url'])
def follow(app, user, args):
account = _find_account(app, user, args.account)
@ -293,15 +314,10 @@ def unfollow(app, user, args):
def whoami(app, user, args):
response = api.verify_credentials(app, user)
account = api.verify_credentials(app, user)
_print_account(account)
print("{} {}".format(green("@" + response['acct']), response['display_name']))
print(response['note'])
print(response['url'])
print("")
print("ID: " + green(response['id']))
print("Since: " + green(response['created_at'][:19].replace('T', ' @ ')))
print("")
print("Followers: " + yellow(response['followers_count']))
print("Following: " + yellow(response['following_count']))
print("Statuses: " + yellow(response['statuses_count']))
def whois(app, user, args):
account = _find_account(app, user, args.account)
_print_account(account)

View File

@ -57,6 +57,16 @@ COMMANDS = [
arguments=[],
require_auth=True,
),
Command(
name="whois",
description="Display user details",
arguments=[
(["account"], {
"help": "account name or numeric ID"
}),
],
require_auth=True,
),
Command(
name="post",
description="Post a status text to your timeline",
@ -178,6 +188,9 @@ def run_command(app, user, name, args):
fn = commands.__dict__.get(name)
if not fn:
raise NotImplementedError("Command '{}' does not have an implementation.".format(name))
return fn(app, user, parsed_args)