diff --git a/dist/yura-14.3.7-py3-none-any.whl b/dist/yura-14.3.7-py3-none-any.whl index f701827..6cbbe8e 100644 Binary files a/dist/yura-14.3.7-py3-none-any.whl and b/dist/yura-14.3.7-py3-none-any.whl differ diff --git a/dist/yura-14.3.7.tar.gz b/dist/yura-14.3.7.tar.gz index 3a7f494..d121bcf 100644 Binary files a/dist/yura-14.3.7.tar.gz and b/dist/yura-14.3.7.tar.gz differ diff --git a/setup.cfg b/setup.cfg index 2829c99..ac5d592 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,3 +18,7 @@ install_requires = [options.packages.find] where = src + +[options.entry_points] +console_scripts = + yura = yura.cli:run diff --git a/src/yura.egg-info/SOURCES.txt b/src/yura.egg-info/SOURCES.txt index 79c79b9..21a0719 100644 --- a/src/yura.egg-info/SOURCES.txt +++ b/src/yura.egg-info/SOURCES.txt @@ -3,9 +3,11 @@ pyproject.toml setup.cfg src/yura/__init__.py src/yura/__main__.py +src/yura/cli.py src/yura/client.py src/yura.egg-info/PKG-INFO src/yura.egg-info/SOURCES.txt src/yura.egg-info/dependency_links.txt +src/yura.egg-info/entry_points.txt src/yura.egg-info/requires.txt src/yura.egg-info/top_level.txt \ No newline at end of file diff --git a/src/yura/client.py b/src/yura/client.py index 5cea3d5..10ef5e0 100644 --- a/src/yura/client.py +++ b/src/yura/client.py @@ -14,10 +14,10 @@ class AsyncClient: self.queue_out = asyncio.Queue() self.communication_task = None - async def ensure_connection(): + async def ensure_connection(self): - if not self.ws: - self.ws = await websockets.connect(self.url) + # if not self.ws: + self.ws = await websockets.connect(self.url) return self.ws @@ -29,6 +29,23 @@ class AsyncClient: return self.communication_task async def chat(self, message): + + ws = await self.ensure_connection() + + await ws.send(json.dumps(message)) + + response = None + while True: + response_raw = await ws.recv() + response = json.loads(response_raw) + if not response["done"]: + yield response + else: + break + if response and response["done"]: + yield response + + async def chatw(self, message): await self.ensure_communication() await self.queue_out.put(message) while True: @@ -66,7 +83,6 @@ class AsyncClient: if response["done"]: break - await self.queue_in.put(response) await self.queue_in.put(response) @@ -87,9 +103,6 @@ async def cli_client(url="ws://127.0.0.1:8470"): print(response["content"], end="", flush=True) - if response["done"]: - break - print("")