Display polls in command line status output
Also display your own votes in toot tui poll displays.
This commit is contained in:
parent
7b194880a0
commit
f15310cc75
2 changed files with 34 additions and 2 deletions
|
@ -168,6 +168,7 @@ def print_status(status, width):
|
||||||
content = reblog['content'] if reblog else status['content']
|
content = reblog['content'] if reblog else status['content']
|
||||||
media_attachments = reblog['media_attachments'] if reblog else status['media_attachments']
|
media_attachments = reblog['media_attachments'] if reblog else status['media_attachments']
|
||||||
in_reply_to = status['in_reply_to_id']
|
in_reply_to = status['in_reply_to_id']
|
||||||
|
poll = reblog['poll'] if reblog else status['poll']
|
||||||
|
|
||||||
time = parse_datetime(status['created_at'])
|
time = parse_datetime(status['created_at'])
|
||||||
time = time.strftime('%Y-%m-%d %H:%M %Z')
|
time = time.strftime('%Y-%m-%d %H:%M %Z')
|
||||||
|
@ -199,6 +200,31 @@ def print_status(status, width):
|
||||||
for line in wc_wrap(url, width):
|
for line in wc_wrap(url, width):
|
||||||
print_out(line)
|
print_out(line)
|
||||||
|
|
||||||
|
if poll:
|
||||||
|
print_out("")
|
||||||
|
for idx, option in enumerate(poll["options"]):
|
||||||
|
perc = (round(100 * option["votes_count"] / poll["votes_count"])
|
||||||
|
if poll["votes_count"] else 0)
|
||||||
|
|
||||||
|
if poll["voted"] and poll["own_votes"] and idx in poll["own_votes"]:
|
||||||
|
voted_for = " <yellow>✓<yellow>"
|
||||||
|
else:
|
||||||
|
voted_for = ""
|
||||||
|
|
||||||
|
print_out(option["title"] + " - {}%".format(perc) + voted_for)
|
||||||
|
|
||||||
|
poll_footer = "Poll · {} votes".format(poll["votes_count"])
|
||||||
|
|
||||||
|
if poll["expired"]:
|
||||||
|
poll_footer += " · Closed"
|
||||||
|
|
||||||
|
if poll["expires_at"]:
|
||||||
|
expires_at = parse_datetime(poll["expires_at"]).strftime("%Y-%m-%d %H:%M")
|
||||||
|
poll_footer += " · Closes on {}".format(expires_at)
|
||||||
|
|
||||||
|
print_out("\n{}".format(poll_footer))
|
||||||
|
|
||||||
|
|
||||||
print_out("\n{}{}{}".format(
|
print_out("\n{}{}{}".format(
|
||||||
"ID <yellow>{}</yellow> ".format(status['id']),
|
"ID <yellow>{}</yellow> ".format(status['id']),
|
||||||
"↲ In reply to <yellow>{}</yellow> ".format(in_reply_to) if in_reply_to else "",
|
"↲ In reply to <yellow>{}</yellow> ".format(in_reply_to) if in_reply_to else "",
|
||||||
|
|
|
@ -328,10 +328,16 @@ class StatusDetails(urwid.Pile):
|
||||||
yield urwid.Text(("link", card["url"]))
|
yield urwid.Text(("link", card["url"]))
|
||||||
|
|
||||||
def poll_generator(self, poll):
|
def poll_generator(self, poll):
|
||||||
for option in poll["options"]:
|
for idx, option in enumerate(poll["options"]):
|
||||||
perc = (round(100 * option["votes_count"] / poll["votes_count"])
|
perc = (round(100 * option["votes_count"] / poll["votes_count"])
|
||||||
if poll["votes_count"] else 0)
|
if poll["votes_count"] else 0)
|
||||||
yield urwid.Text(option["title"])
|
|
||||||
|
if poll["voted"] and poll["own_votes"] and idx in poll["own_votes"]:
|
||||||
|
voted_for = " ✓"
|
||||||
|
else:
|
||||||
|
voted_for = ""
|
||||||
|
|
||||||
|
yield urwid.Text(option["title"] + voted_for)
|
||||||
yield urwid.ProgressBar("", "poll_bar", perc)
|
yield urwid.ProgressBar("", "poll_bar", perc)
|
||||||
|
|
||||||
status = "Poll · {} votes".format(poll["votes_count"])
|
status = "Poll · {} votes".format(poll["votes_count"])
|
||||||
|
|
Loading…
Reference in a new issue