From c03343a19284afb976820f969bddee233391ca69 Mon Sep 17 00:00:00 2001 From: Vincent Texier <vit@free.fr> Date: Wed, 8 Aug 2018 10:57:45 +0200 Subject: [PATCH] issue #56 add ES_USER_API example --- README.rst | 2 +- examples/request_data_elasticsearch.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 326caad2..fb2df881 100644 --- a/README.rst +++ b/README.rst @@ -41,7 +41,7 @@ Please take a look at the document `HTTP API <https://git.duniter.org/nodes/type Development ----------- -* Create a python environment with `pyenv <https://github.com/pyenv/pyenv>`_ :: +* Create a python virtual environment with `pyenv <https://github.com/pyenv/pyenv>`_ :: curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash` diff --git a/examples/request_data_elasticsearch.py b/examples/request_data_elasticsearch.py index ba4d1959..a93c70a3 100644 --- a/examples/request_data_elasticsearch.py +++ b/examples/request_data_elasticsearch.py @@ -11,6 +11,7 @@ from duniterpy.api.client import Client # or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] # Here we use the secure BASIC_MERKLED_API (BMAS) ES_CORE_ENDPOINT = "ES_CORE_API g1-test.data.duniter.fr 443" +ES_USER_ENDPOINT = "ES_USER_API g1-test.data.duniter.fr 443" ################################################ @@ -36,6 +37,20 @@ async def main(): # Close client aiohttp session await client.close() + # Create Client from endpoint string in Duniter format + client = Client(ES_USER_ENDPOINT) + + # prompt entry + pubkey = input("\nEnter a public key to get the user profile: ") + + # Get the profil of a public key (direct REST GET request) + print("\nGET user/profile/{0}/_source:".format(pubkey)) + response = await client.get('user/profile/{0}/_source'.format(pubkey.strip(' \n'))) + print(response) + + # Close client aiohttp session + await client.close() + # Latest duniter-python-api is asynchronous and you have to use asyncio, an asyncio loop and a "as" on the data. # ( https://docs.python.org/3/library/asyncio.html ) -- GitLab