Introduction
Introduction Statistics Contact Development Disclaimer Help
Move printing logic to output - toot - Unnamed repository; edit this file 'desc…
Log
Files
Refs
LICENSE
---
commit 787e0d28b4cd9d77d7948da80874d17942e9c330
parent dfdad045f00b3faa9679989031d0a4dabe4753ce
Author: Ivan Habunek <[email protected]>
Date: Fri, 29 Dec 2017 14:42:51 +0100
Move printing logic to output
Diffstat:
toot/commands.py | 52 +++----------------------------
toot/output.py | 42 ++++++++++++++++++++++++++++++-
2 files changed, 46 insertions(+), 48 deletions(-)
---
diff --git a/toot/commands.py b/toot/commands.py
@@ -8,10 +8,10 @@ from datetime import datetime
from itertools import zip_longest
from getpass import getpass
from itertools import chain
-from textwrap import TextWrapper, wrap
+from textwrap import TextWrapper
from toot import api, config, DEFAULT_INSTANCE, User, App, ConsoleError
-from toot.output import print_out, print_instance
+from toot.output import print_out, print_instance, print_account, print_search…
def register_app(instance):
@@ -213,31 +213,9 @@ def upload(app, user, args):
print_out("Text URL: <green>{}</green>".format(response['text_url']))
-def _print_accounts(accounts):
- if not accounts:
- return
-
- print_out("\nAccounts:")
- for account in accounts:
- print_out("* <green>@{}</green> {}".format(
- account['acct'],
- account['display_name']
- ))
-
-
-def _print_hashtags(hashtags):
- if not hashtags:
- return
-
- print_out("\nHashtags:")
- print_out(", ".join(["<green>#{}</green>".format(t) for t in hashtags]))
-
-
def search(app, user, args):
response = api.search(app, user, args.query, args.resolve)
-
- _print_accounts(response['accounts'])
- _print_hashtags(response['hashtags'])
+ print_search_results(response)
def _do_upload(app, user, file):
@@ -265,26 +243,6 @@ def _find_account(app, user, account_name):
raise ConsoleError("Account not found")
-def _print_account(account):
- print_out("<green>@{}</green> {}".format(account['acct'], account['display…
-
- note = BeautifulSoup(account['note'], "html.parser").get_text()
-
- if note:
- print_out("")
- print_out("\n".join(wrap(note)))
-
- print_out("")
- print_out("ID: <green>{}</green>".format(account['id']))
- print_out("Since: <green>{}</green>".format(account['created_at'][:19].rep…
- print_out("")
- print_out("Followers: <yellow>{}</yellow>".format(account['followers_count…
- print_out("Following: <yellow>{}</yellow>".format(account['following_count…
- print_out("Statuses: <yellow>{}</yellow>".format(account['statuses_count']…
- print_out("")
- print_out(account['url'])
-
-
def follow(app, user, args):
account = _find_account(app, user, args.account)
api.follow(app, user, account['id'])
@@ -323,12 +281,12 @@ def unblock(app, user, args):
def whoami(app, user, args):
account = api.verify_credentials(app, user)
- _print_account(account)
+ print_account(account)
def whois(app, user, args):
account = _find_account(app, user, args.account)
- _print_account(account)
+ print_account(account)
def instance(app, user, args):
diff --git a/toot/output.py b/toot/output.py
@@ -4,7 +4,7 @@ import sys
import re
from textwrap import wrap
-from toot.utils import format_content
+from toot.utils import format_content, get_text
START_CODES = {
'red': '\033[31m',
@@ -70,3 +70,43 @@ def print_instance(instance):
for l in wrap(line.strip()):
print(l)
print()
+
+
+def print_account(account):
+ print_out("<green>@{}</green> {}".format(account['acct'], account['display…
+
+ note = get_text(account['note'])
+
+ if note:
+ print_out("")
+ print_out("\n".join(wrap(note)))
+
+ print_out("")
+ print_out("ID: <green>{}</green>".format(account['id']))
+ print_out("Since: <green>{}</green>".format(account['created_at'][:19].rep…
+ print_out("")
+ print_out("Followers: <yellow>{}</yellow>".format(account['followers_count…
+ print_out("Following: <yellow>{}</yellow>".format(account['following_count…
+ print_out("Statuses: <yellow>{}</yellow>".format(account['statuses_count']…
+ print_out("")
+ print_out(account['url'])
+
+
+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']
+ ))
+
+ if hashtags:
+ print_out("\nHashtags:")
+ print_out(", ".join(["<green>#{}</green>".format(t) for t in hashtags]…
+
+ if not accounts and not hashtags:
+ print_out("<yellow>Nothing found</yellow>")
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.