From 1709a416b34795b0ed724038e076e0532b8065f5 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Sat, 9 Mar 2024 09:32:38 +0100 Subject: [PATCH] Make list printing not break on akkoma --- toot/cli/lists.py | 11 +++++++---- toot/output.py | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/toot/cli/lists.py b/toot/cli/lists.py index f0d4ae6..65d7d2d 100644 --- a/toot/cli/lists.py +++ b/toot/cli/lists.py @@ -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.") diff --git a/toot/output.py b/toot/output.py index aeaeb6a..88f65ed 100644 --- a/toot/output.py +++ b/toot/output.py @@ -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)