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

Move printing logic to output

This commit is contained in:
Ivan Habunek 2017-12-29 14:42:51 +01:00
parent dfdad045f0
commit 787e0d28b4
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
2 changed files with 46 additions and 48 deletions

View File

@ -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_results
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_name']))
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].replace('T', ' @ ')))
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):

View File

@ -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_name']))
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].replace('T', ' @ ')))
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>")