Skip to content

Commit

Permalink
Extract code for printing a poll
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Nov 29, 2022
1 parent f15310c commit 916b4cc
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions toot/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,35 +201,38 @@ def print_status(status, width):
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)
print_poll(poll)

if poll["voted"] and poll["own_votes"] and idx in poll["own_votes"]:
voted_for = " <yellow>✓<yellow>"
else:
voted_for = ""
print_out("\n{}{}{}".format(
"ID <yellow>{}</yellow> ".format(status['id']),
"↲ In reply to <yellow>{}</yellow> ".format(in_reply_to) if in_reply_to else "",
"↻ Reblogged <blue>@{}</blue> ".format(reblog['account']['acct']) if reblog else "",
))

print_out(option["title"] + " - {}%".format(perc) + voted_for)

poll_footer = "Poll · {} votes".format(poll["votes_count"])
def print_poll(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["expired"]:
poll_footer += " · Closed"
if poll["voted"] and poll["own_votes"] and idx in poll["own_votes"]:
voted_for = " <yellow>✓</yellow>"
else:
voted_for = ""

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(f'{option["title"]} - {perc}% {voted_for}')

print_out("\n{}".format(poll_footer))
poll_footer = f'Poll · {poll["votes_count"]} votes'

if poll["expired"]:
poll_footer += " · Closed"

print_out("\n{}{}{}".format(
"ID <yellow>{}</yellow> ".format(status['id']),
"↲ In reply to <yellow>{}</yellow> ".format(in_reply_to) if in_reply_to else "",
"↻ Reblogged <blue>@{}</blue> ".format(reblog['account']['acct']) if reblog else "",
))
if poll["expires_at"]:
expires_at = parse_datetime(poll["expires_at"]).strftime("%Y-%m-%d %H:%M")
poll_footer += f" · Closes on {expires_at}"

print_out("\n{}".format(poll_footer))


def print_timeline(items, width=100):
Expand Down

0 comments on commit 916b4cc

Please sign in to comment.