Add `toot polls show`

pull/493/merge
Ivan Habunek 2025-08-05 10:52:32 +02:00
rodzic 23b48e15aa
commit a7f1ce83e9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 01DB3DD0D824504C
4 zmienionych plików z 38 dodań i 0 usunięć

Wyświetl plik

@ -735,6 +735,10 @@ def get_lists(app, user):
return http.get(app, user, "/api/v1/lists").json()
def get_poll(app, user, poll_id):
return http.get(app, user, f"/api/v1/polls/{poll_id}").json()
def get_list_accounts(app, user, list_id):
path = f"/api/v1/lists/{list_id}/accounts"
return _get_response_list(app, user, path)

Wyświetl plik

@ -187,6 +187,7 @@ from toot.cli import accounts # noqa
from toot.cli import auth # noqa
from toot.cli import diag # noqa
from toot.cli import lists # noqa
from toot.cli import polls # noqa
from toot.cli import post # noqa
from toot.cli import read # noqa
from toot.cli import statuses # noqa

28
toot/cli/polls.py 100644
Wyświetl plik

@ -0,0 +1,28 @@
import json as pyjson
import click
from toot import api
from toot.cli import Context, cli, json_option, pass_context
from toot.entities import Poll, from_dict
from toot.output import print_poll
@cli.group()
def polls():
"""Show and vote on polls"""
pass
@polls.command()
@click.argument("poll_id")
@json_option
@pass_context
def show(ctx: Context, poll_id: str, json: bool):
"""Show a poll by ID"""
data = api.get_poll(ctx.app, ctx.user, poll_id)
if json:
click.echo(pyjson.dumps(data))
else:
poll = from_dict(Poll, data)
print_poll(poll)

Wyświetl plik

@ -245,6 +245,11 @@ def html_lines(html: str, width: int) -> t.Generator[str, None, None]:
first = False
def print_poll(poll: Poll):
for line in poll_lines(poll):
print(line)
def poll_lines(poll: Poll) -> t.Generator[str, None, None]:
for idx, option in enumerate(poll.options):
perc = (