kopia lustrzana https://github.com/ihabunek/toot
Add `toot polls show`
rodzic
23b48e15aa
commit
a7f1ce83e9
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
|
@ -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 = (
|
||||
|
|
Ładowanie…
Reference in New Issue