From 17fb11aabbea3c5e5ffce4f07ee857643f6c7a6d Mon Sep 17 00:00:00 2001
From: matograine <tom.ngr@zaclys.net>
Date: Mon, 20 Jun 2022 22:20:18 +0200
Subject: [PATCH] [enh] wot: Migrate from tabulate to texttable (#203)

---
 silkaj/wot.py       | 24 +++++++++++++-----------
 tests/test_money.py |  4 +---
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/silkaj/wot.py b/silkaj/wot.py
index ea2671e1..afedd551 100644
--- a/silkaj/wot.py
+++ b/silkaj/wot.py
@@ -20,14 +20,13 @@ from typing import Dict, List, Tuple
 import click
 from duniterpy.api.bma import blockchain, wot
 from pendulum import from_timestamp, now
-from tabulate import tabulate
 
 from silkaj import wot_tools as wt
 from silkaj.blockchain_tools import get_blockchain_parameters
 from silkaj.constants import DATE
 from silkaj.crypto_tools import is_pubkey_and_check
 from silkaj.network_tools import client_instance, exit_on_http_error
-from silkaj.tui import gen_pubkey_checksum
+from silkaj.tui import Table, gen_pubkey_checksum
 
 
 def get_sent_certifications(
@@ -78,6 +77,8 @@ def received_sent_certifications(uid_pubkey: str) -> None:
 
     certifications["received_expire"] = []
     certifications["received"] = []
+    certifications["sent"] = []
+    certifications["sent_expire"] = []
     for cert in identity["others"]:
         certifications["received_expire"].append(
             expiration_date_from_block_id(
@@ -92,15 +93,16 @@ def received_sent_certifications(uid_pubkey: str) -> None:
             certifications["sent_expire"],
         ) = get_sent_certifications(signed, time_first_block, params)
     nbr_sent_certs = len(certifications["sent"]) if "sent" in certifications else 0
-    table = tabulate(
-        certifications, headers="keys", tablefmt="orgtbl", stralign="right"
-    )
+
+    table = Table(style="columns").set_cols_align(["r", "r", "r", "r"])
+    table.fill_from_dict(certifications)
+
     print(
         f'{identity["uid"]} ({gen_pubkey_checksum(pubkey, True)}) \
 from block #{identity["meta"]["timestamp"][:15]}…\n\
-received {len(certifications["received"])} and \
-sent {nbr_sent_certs}/{params["sigStock"]} certifications:\n\
-{table}\n\
+received {len(certifications["received"])} and sent \
+{nbr_sent_certs}/{params["sigStock"]} certifications:\n\
+{table.draw()}\n\
 ✔: Certification available to be written or already written into the blockchain\n'
     )
     membership_status(certifications, pubkey, req)
@@ -203,9 +205,9 @@ def choose_identity(pubkey_uid: str) -> Tuple[Dict, str, List]:
         pubkey_index = 0
         uid_index = 0
     elif identities > 1:
-        table = tabulate(identities_choices, headers="keys", tablefmt="orgtbl")
-        click.echo(table)
-
+        table = Table().set_cols_dtype(["t", "t", "t", "t"])
+        table.fill_from_dict(identities_choices)
+        click.echo(table.draw())
         # Loop till the passed value is in identities_choices
         message = "Which identity would you like to select (id)?"
         selected_id = None
diff --git a/tests/test_money.py b/tests/test_money.py
index 26774e55..42170b17 100644
--- a/tests/test_money.py
+++ b/tests/test_money.py
@@ -19,9 +19,7 @@ from click.testing import CliRunner
 from silkaj.cli import cli
 from silkaj.constants import FAILURE_EXIT_STATUS
 from silkaj.money import get_sources
-
-# had to import from wot to prevent loop dependencies
-from silkaj.wot import gen_pubkey_checksum
+from silkaj.tui import gen_pubkey_checksum
 
 
 def test_get_sources(monkeypatch):
-- 
GitLab