Introduction
Introduction Statistics Contact Development Disclaimer Help
Add whois command - toot - Unnamed repository; edit this file 'description' to …
Log
Files
Refs
LICENSE
---
commit 9b48432d04d7ea7904ede5e18b8790ec9765eb56
parent e1c993b9d0f90eb4e9a426c6dcfe33bda15b5746
Author: Ivan Habunek <[email protected]>
Date: Wed, 19 Apr 2017 15:29:40 +0200
Add whois command
Diffstat:
toot/commands.py | 42 +++++++++++++++++++++----------
toot/console.py | 13 +++++++++++++
2 files changed, 42 insertions(+), 13 deletions(-)
---
diff --git a/toot/commands.py b/toot/commands.py
@@ -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 fou…
+ """For a given account name, returns the Account object or raises an excep…
response = api.search(app, user, account_name, False)
for account in response['accounts']:
if account['acct'] == account_name or "@" + account['acct'] == account…
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)
diff --git a/toot/console.py b/toot/console.py
@@ -58,6 +58,16 @@ COMMANDS = [
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",
arguments=[
@@ -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 implementatio…
+
return fn(app, user, parsed_args)
You are viewing proxied material from vernunftzentrum.de. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.