diff --git a/silkaj/wot.py b/silkaj/wot.py index f88a6f5233a9d35e5cf5f42f505e882e9b2e8f61..dc1016f86f0cb7115f62288fa36746912b7926d4 100644 --- a/silkaj/wot.py +++ b/silkaj/wot.py @@ -18,7 +18,7 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>. import click import pendulum from time import time -from tabulate import tabulate + from collections import OrderedDict from duniterpy.api.bma import wot, blockchain from duniterpy.api.errors import DuniterError @@ -27,7 +27,12 @@ from silkaj import wot_tools as wt from silkaj.network_tools import ClientInstance from silkaj.crypto_tools import is_pubkey_and_check from silkaj.tools import coroutine -from silkaj.tui import display_pubkey_and_checksum +from silkaj.tui import ( + display_pubkey_and_checksum, + create_table, + fill_table_from_dict_list, + fill_table_from_dict, +) from silkaj.blockchain_tools import BlockchainParams from silkaj.constants import DATE @@ -87,6 +92,7 @@ async def received_sent_certifications(uid_pubkey): certifications["sent_expire"], ) = get_sent_certifications(signed, time_first_block, params) nbr_sent_certs = len(certifications["sent"]) if "sent" in certifications else 0 + table = create_table(style="columns") print( "{0} ({1}) from block #{2}\nreceived {3} and sent {4}/{5} certifications:\n{6}\n{7}\n".format( identity["uid"], @@ -95,12 +101,7 @@ async def received_sent_certifications(uid_pubkey): len(certifications["received"]), nbr_sent_certs, params["sigStock"], - tabulate( - certifications, - headers="keys", - tablefmt="orgtbl", - stralign="center", - ), + fill_table_from_dict(table, certifications), "✔: Certification available to be written or already written into the blockchain", ) ) @@ -189,7 +190,9 @@ async def choose_identity(pubkey_uid): lookups = await wt.wot_lookup(pubkey_uid) # Generate table containing the choices - identities_choices = {"id": [], "uid": [], "pubkey": [], "timestamp": []} + identities_choices = OrderedDict( + [("id", []), ("uid", []), ("pubkey", []), ("timestamp", [])] + ) for pubkey_index, lookup in enumerate(lookups): for uid_index, identity in enumerate(lookup["uids"]): identities_choices["id"].append(str(pubkey_index) + str(uid_index)) @@ -206,9 +209,10 @@ async def choose_identity(pubkey_uid): pubkey_index = 0 uid_index = 0 elif identities > 1: - table = tabulate(identities_choices, headers="keys", tablefmt="orgtbl") + table = create_table() + table.set_cols_dtype(["t", "t", "t", "t"]) + table = fill_table_from_dict(table, identities_choices) click.echo(table) - # Loop till the passed value is in identities_choices message = "Which identity would you like to select (id)?" selected_id = None