From d0c23186c9f8d5607344da3625f3c5f038e8bd36 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Sun, 7 Jun 2020 22:07:32 +0200 Subject: [PATCH] [mod] #269: Move convert_time() to tui.py --- silkaj/cert.py | 3 ++- silkaj/commands.py | 3 ++- silkaj/net.py | 3 ++- silkaj/tools.py | 17 ----------------- silkaj/tui.py | 18 ++++++++++++++++++ silkaj/tx_history.py | 3 ++- silkaj/wot.py | 3 ++- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/silkaj/cert.py b/silkaj/cert.py index 434ad978..fc5682b4 100644 --- a/silkaj/cert.py +++ b/silkaj/cert.py @@ -23,7 +23,8 @@ from duniterpy.api.bma import wot, blockchain from duniterpy.documents import BlockUID, block_uid, Identity, Certification from silkaj.auth import auth_method -from silkaj.tools import convert_time, message_exit, coroutine +from silkaj.tools import message_exit, coroutine +from silkaj.tui import convert_time from silkaj.network_tools import ClientInstance, HeadBlock from silkaj.blockchain_tools import BlockchainParams from silkaj.license import license_approval diff --git a/silkaj/commands.py b/silkaj/commands.py index cbf205f2..6de07d44 100644 --- a/silkaj/commands.py +++ b/silkaj/commands.py @@ -35,7 +35,8 @@ from silkaj.network_tools import ( ClientInstance, HeadBlock, ) -from silkaj.tools import convert_time, CurrencySymbol +from silkaj.tools import CurrencySymbol +from silkaj.tui import convert_time from silkaj.constants import ASYNC_SLEEP diff --git a/silkaj/net.py b/silkaj/net.py index 68f7f10d..3082ae53 100644 --- a/silkaj/net.py +++ b/silkaj/net.py @@ -33,7 +33,8 @@ from silkaj.network_tools import ( best_endpoint_address, ClientInstance, ) -from silkaj.tools import convert_time, message_exit +from silkaj.tools import message_exit +from silkaj.tui import convert_time from silkaj.constants import ASYNC_SLEEP diff --git a/silkaj/tools.py b/silkaj/tools.py index 4c16d541..997349dc 100644 --- a/silkaj/tools.py +++ b/silkaj/tools.py @@ -15,7 +15,6 @@ You should have received a copy of the GNU Affero General Public License along with Silkaj. If not, see <https://www.gnu.org/licenses/>. """ -from datetime import datetime from sys import exit from asyncio import get_event_loop from functools import update_wrapper @@ -24,22 +23,6 @@ from silkaj.constants import G1_SYMBOL, GTEST_SYMBOL, FAILURE_EXIT_STATUS from silkaj.blockchain_tools import BlockchainParams -def convert_time(timestamp, kind): - ts = int(timestamp) - date = "%Y-%m-%d" - hour = "%H:%M" - second = ":%S" - if kind == "all": - pattern = date + " " + hour + second - elif kind == "date": - pattern = date - elif kind == "hour": - pattern = hour - if ts >= 3600: - pattern += second - return datetime.fromtimestamp(ts).strftime(pattern) - - class CurrencySymbol(object): __instance = None diff --git a/silkaj/tui.py b/silkaj/tui.py index 106fae15..dc6af41c 100644 --- a/silkaj/tui.py +++ b/silkaj/tui.py @@ -15,6 +15,8 @@ You should have received a copy of the GNU Affero General Public License along with Silkaj. If not, see <https://www.gnu.org/licenses/>. """ +from datetime import datetime + from silkaj import wot @@ -43,3 +45,19 @@ async def display_pubkey(tx, message, pubkey): id = await wot.is_member(pubkey) if id: tx.append([message + " (id)", id["uid"]]) + + +def convert_time(timestamp, kind): + ts = int(timestamp) + date = "%Y-%m-%d" + hour = "%H:%M" + second = ":%S" + if kind == "all": + pattern = date + " " + hour + second + elif kind == "date": + pattern = date + elif kind == "hour": + pattern = hour + if ts >= 3600: + pattern += second + return datetime.fromtimestamp(ts).strftime(pattern) diff --git a/silkaj/tx_history.py b/silkaj/tx_history.py index 35e94c34..ea86cb4e 100644 --- a/silkaj/tx_history.py +++ b/silkaj/tx_history.py @@ -22,7 +22,8 @@ from time import time from duniterpy.api.bma.tx import history from duniterpy.documents.transaction import Transaction from silkaj.network_tools import ClientInstance -from silkaj.tools import convert_time, coroutine +from silkaj.tools import coroutine +from silkaj.tui import convert_time from silkaj.crypto_tools import check_public_key from silkaj.wot import identity_of, identities_from_pubkeys from silkaj.money import get_amount_from_pubkey, amount_in_current_base, UDValue diff --git a/silkaj/wot.py b/silkaj/wot.py index 1c269f46..ba97ecf8 100644 --- a/silkaj/wot.py +++ b/silkaj/wot.py @@ -25,7 +25,8 @@ from duniterpy.api.errors import DuniterError from silkaj.network_tools import ClientInstance from silkaj.crypto_tools import check_public_key -from silkaj.tools import message_exit, convert_time, coroutine +from silkaj.tools import message_exit, coroutine +from silkaj.tui import convert_time from silkaj.blockchain_tools import BlockchainParams from silkaj.constants import ASYNC_SLEEP -- GitLab