From febdfaf355f41149659c9eeb4efbc0d2604e284b Mon Sep 17 00:00:00 2001 From: c0de Date: Fri, 9 Dec 2022 23:20:54 -0600 Subject: [PATCH] Format points table with beautifultable --- game/points.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/game/points.py b/game/points.py index b0bc284..c4664ba 100644 --- a/game/points.py +++ b/game/points.py @@ -4,6 +4,8 @@ # pylint: disable=not-an-iterable,missing-module-docstring,too-few-public-methods +from beautifultable import BeautifulTable + from database.models import PlayerModel as Player from game.base import BaseGameManager @@ -23,22 +25,23 @@ class PointsManager(BaseGameManager): message = ( "\nPlayers, who played recently, with their points highest to lowest\n\n" ) - message += "Player | Total Points | Last Played\n" + + message += "```\n" + table = BeautifulTable() + table.column_headers = ["Player", "Total Points", "Last Played"] players = Player.select( Player.player_name, Player.total_points, Player.last_update ).order_by(Player.last_update.desc(), Player.total_points.desc()) for player in players: - message += ( - " | ".join( - [ - player.player_name, - str(player.total_points), - str(player.last_update)[:-10], - ] - ) - + "\n" - ) + table.rows.append([ + player.player_name, + str(player.total_points), + str(player.last_update)[:-10], + ]) + + message += str(table) + message += "\n```\n" return await self.message.channel.send(message)