Extract code for printing a poll

This commit is contained in:
Ivan Habunek 2022-11-29 09:20:00 +01:00
parent f15310cc75
commit 916b4cc4bf
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
1 changed files with 26 additions and 23 deletions

View File

@ -201,29 +201,7 @@ 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)
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_poll(poll)
print_out("\n{}{}{}".format(
"ID <yellow>{}</yellow> ".format(status['id']),
@ -232,6 +210,31 @@ def print_status(status, width):
))
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["voted"] and poll["own_votes"] and idx in poll["own_votes"]:
voted_for = " <yellow>✓</yellow>"
else:
voted_for = ""
print_out(f'{option["title"]} - {perc}% {voted_for}')
poll_footer = f'Poll · {poll["votes_count"]} votes'
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 += f" · Closes on {expires_at}"
print_out("\n{}".format(poll_footer))
def print_timeline(items, width=100):
print_out("" * width)
for item in items: