From 66839fc8055ab4476ddadab2b482a251323264af Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Mon, 24 May 2021 16:38:19 +0200 Subject: [PATCH] [mod] #256: Add code handling the display of the name of the user stored in CS+ --- silkaj/constants.py | 5 +++++ silkaj/excluded.py | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/silkaj/constants.py b/silkaj/constants.py index a93e60ab..c20f9fc1 100644 --- a/silkaj/constants.py +++ b/silkaj/constants.py @@ -16,9 +16,14 @@ SILKAJ_VERSION = "0.10.0dev" G1_SYMBOL = "Äž1" GTEST_SYMBOL = "ÄžTest" + G1_DEFAULT_ENDPOINT = "BMAS g1.duniter.org 443" G1_TEST_DEFAULT_ENDPOINT = "BMAS g1-test.duniter.org 443" +G1_CSP_USER_ENDPOINT = "ES_USER_API g1.data.e-is.pro 443" +# G1_CSP_USER_ENDPOINT = "ES_USER_API g1.data.presles.fr 443" +GTEST_CSP_USER_ENDPOINT = "ES_USER_API g1-test.data.e-is.pro 443" + ONE_HOUR = 3600 SUCCESS_EXIT_STATUS = 0 diff --git a/silkaj/excluded.py b/silkaj/excluded.py index ed5cc99d..46c76f2a 100644 --- a/silkaj/excluded.py +++ b/silkaj/excluded.py @@ -139,6 +139,10 @@ def gen_message_over_blocks(bma_client, blocks_to_process, params): Loop over the list of blocks to retrieve and parse the blocks Ignore revocation kind of exclusion """ + if params["currency"] == dp_const.G1_CURRENCY_CODENAME: + es_client = Client(constants.G1_CSP_USER_ENDPOINT) + else: + es_client = Client(constants.GTEST_CSP_USER_ENDPOINT) message = "" for block_number in blocks_to_process: logging.info(f"Processing block number {block_number}") @@ -155,7 +159,7 @@ def gen_message_over_blocks(bma_client, blocks_to_process, params): if block.revoked and block.excluded[0] == block.revoked[0].pubkey: continue - message += await generate_message(block, block_hash, params) + message += generate_message(es_client, block, block_hash, params) return message @@ -171,7 +175,7 @@ def gen_header(blocks_to_process): return header + message_g1 -def generate_message(block, block_hash, params): +def generate_message(es_client, block, block_hash, params): """ Loop over exclusions within a block Generate identity header + info @@ -181,12 +185,20 @@ def generate_message(block, block_hash, params): lookup = wot_tools.wot_lookup(excluded)[0] uid = lookup["uids"][0]["uid"] + pubkey = lookup["pubkey"] + try: + response = es_client.get(f"user/profile/{pubkey}/_source") + es_uid = response["title"] + except urllib.error.HTTPError: + es_uid = uid + logging.info("Cesium+ API: Not found pubkey or connection error") + if params["currency"] == dp_const.G1_CURRENCY_CODENAME: cesium_url = G1_CESIUM_URL else: cesium_url = GTEST_CESIUM_URL cesium_url += CESIUM_BLOCK_PATH - message += f"\n\n### @{uid} [{uid}]({cesium_url}{block.number}/{block_hash}?ssl=true)\n" + message += f"\n\n### @{uid} [{es_uid}]({cesium_url}{block.number}/{block_hash}?ssl=true)\n" message += generate_identity_info(lookup, block, params) return message -- GitLab