From 525252ecabc51ede7d361a4cd82ed30c24eb1ac0 Mon Sep 17 00:00:00 2001
From: matograine <tom.ngr@zaclys.net>
Date: Mon, 26 Apr 2021 17:09:36 +0200
Subject: [PATCH] [mod] #344 use pendulum in silkaj.wot   * change alignment
 for wot table for easy date reading

---
 silkaj/wot.py | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/silkaj/wot.py b/silkaj/wot.py
index 366c696a..43d48485 100644
--- a/silkaj/wot.py
+++ b/silkaj/wot.py
@@ -16,7 +16,7 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
 """
 
 import click
-from time import time
+from pendulum import from_timestamp, now
 from tabulate import tabulate
 from collections import OrderedDict
 from asyncio import sleep
@@ -26,9 +26,9 @@ from duniterpy.api.errors import DuniterError
 from silkaj.network_tools import ClientInstance
 from silkaj.crypto_tools import is_pubkey_and_check
 from silkaj.tools import message_exit, coroutine
-from silkaj.tui import convert_time, display_pubkey_and_checksum
+from silkaj.tui import display_pubkey_and_checksum
 from silkaj.blockchain_tools import BlockchainParams
-from silkaj.constants import ASYNC_SLEEP
+from silkaj.constants import ASYNC_SLEEP, DATE
 
 
 def get_sent_certifications(signed, time_first_block, params):
@@ -98,7 +98,7 @@ async def received_sent_certifications(uid_pubkey):
                 certifications,
                 headers="keys",
                 tablefmt="orgtbl",
-                stralign="center",
+                stralign="right",
             ),
             "✔: Certification available to be written or already written into the blockchain",
         )
@@ -128,29 +128,23 @@ async def membership_status(certifications, pubkey, req):
         member = True
     print("member:", member)
     if req["revoked"]:
-        print(
-            "revoked:",
-            req["revoked"],
-            "\nrevoked on:",
-            convert_time(req["revoked_on"], "date") + "\n",
-        )
+        revoke_date = from_timestamp(req["revoked_on"], tz="local").format(DATE)
+        print(f"revoked: {req['revoked']}\nrevoked on: {revoke_date}")
     if not member and req["wasMember"]:
         print("expired:", req["expired"], "\nwasMember:", req["wasMember"])
     elif member:
-        print(
-            "Membership document expiration: "
-            + convert_time(time() + req["membershipExpiresIn"], "date")
-        )
+        expiration_date = now().add(seconds=req["membershipExpiresIn"]).format(DATE)
+        print(f"Membership document expiration: {expiration_date}")
         print("Sentry:", req["isSentry"])
     print("outdistanced:", req["outdistanced"])
 
 
 def expiration_date_from_block_id(block_id, time_first_block, params):
-    return convert_time(
+    expir_timestamp = (
         date_approximation(block_id, time_first_block, params["avgGenTime"])
-        + params["sigValidity"],
-        "date",
+        + params["sigValidity"]
     )
+    return from_timestamp(expir_timestamp, tz="local").format(DATE)
 
 
 def date_approximation(block_id, time_first_block, avgentime):
-- 
GitLab