Make list printing not break on akkoma

This commit is contained in:
Ivan Habunek 2024-03-09 09:32:38 +01:00
parent f324aa119d
commit 1709a416b3
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
2 changed files with 10 additions and 7 deletions

View File

@ -3,6 +3,7 @@ import json as pyjson
from toot import api, config
from toot.cli import Context, cli, pass_context, json_option
from toot.entities import from_dict_list, List
from toot.output import print_list_accounts, print_lists, print_warning
@ -18,7 +19,8 @@ def lists(ctx: click.Context):
if not user or not app:
raise click.ClickException("This command requires you to be logged in.")
lists = api.get_lists(app, user)
data = api.get_lists(app, user)
lists = from_dict_list(List, data)
if lists:
print_lists(lists)
else:
@ -30,12 +32,13 @@ def lists(ctx: click.Context):
@pass_context
def list(ctx: Context, json: bool):
"""List all your lists"""
lists = api.get_lists(ctx.app, ctx.user)
data = api.get_lists(ctx.app, ctx.user)
if json:
click.echo(pyjson.dumps(lists))
click.echo(pyjson.dumps(data))
else:
if lists:
if data:
lists = from_dict_list(List, data)
print_lists(lists)
else:
click.echo("You have no lists defined.")

View File

@ -4,7 +4,7 @@ import shutil
import textwrap
import typing as t
from toot.entities import Account, Instance, Notification, Poll, Status
from toot.entities import Account, Instance, Notification, Poll, Status, List
from toot.utils import get_text, html_to_paragraphs
from toot.wcstring import wc_wrap
from wcwidth import wcswidth
@ -119,9 +119,9 @@ def print_tag_list(tags):
click.echo(f"* {format_tag_name(tag)}\t{tag['url']}")
def print_lists(lists):
def print_lists(lists: t.List[List]):
headers = ["ID", "Title", "Replies"]
data = [[lst["id"], lst["title"], lst["replies_policy"]] for lst in lists]
data = [[lst.id, lst.title, lst.replies_policy or ""] for lst in lists]
print_table(headers, data)