neuronum 1.2.2__py3-none-any.whl → 1.2.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of neuronum might be problematic. Click here for more details.

neuronum/neuronum.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import requests
2
2
  import socket
3
- from typing import Optional
3
+ from typing import Optional, Generator
4
4
  import ssl
5
5
  from websocket import create_connection
6
6
  from typing import List
@@ -207,37 +207,38 @@ class Cell:
207
207
  return "Authentication successful" in response
208
208
 
209
209
 
210
- def sync(self, stx: Optional[str] = None) -> List[str]:
211
- stream = []
212
- try:
213
- auth = {
214
- "host": self.host,
215
- "password": self.password,
216
- "synapse": self.synapse,
217
- }
218
-
219
- ws = create_connection(f"wss://{self.network}/sync/{stx}")
220
- ws.settimeout(1)
221
- print(f"Auth Payload: {auth}")
222
- ws.send(json.dumps(auth))
223
-
224
- except Exception as e:
225
- print(f"Failed to connect: {e}")
226
- return stream
210
+ def sync(self, stx: Optional[str] = None) -> Generator[str, None, None]:
211
+ auth = {
212
+ "host": self.host,
213
+ "password": self.password,
214
+ "synapse": self.synapse,
215
+ }
216
+ print(f"Auth Payload: {auth}")
227
217
 
228
- try:
229
- while True:
230
- message = ws.recv()
231
- print(f"Received Data: {message}")
232
- stream.append(message)
233
- except KeyboardInterrupt:
234
- print("Closing connection...")
235
- except Exception as e:
236
- print(f"Error during data collection: {e}")
237
- finally:
238
- ws.close()
239
- print("Connection closed.")
218
+ while True:
219
+ try:
220
+ ws = create_connection(f"wss://{self.network}/sync/{stx}")
221
+ ws.settimeout(1)
222
+ ws.send(json.dumps(auth))
223
+ print("Connected to WebSocket.")
224
+
225
+ while True:
226
+ try:
227
+ raw_operation = ws.recv()
228
+ operation = json.loads(raw_operation)
229
+ yield operation
230
+ except socket.timeout:
231
+ print("Timeout occurred, no data received.")
232
+ except KeyboardInterrupt:
233
+ print("Closing connection...")
234
+ ws.close()
235
+ return
236
+ except Exception as e:
237
+ print(f"Connection failed: {e}")
238
+ finally:
239
+ if ws:
240
+ ws.close()
241
+ print("Connection closed, retrying...")
240
242
 
241
- return stream
242
243
 
243
244
  __all__ = ['Cell']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neuronum
3
- Version: 1.2.2
3
+ Version: 1.2.4
4
4
  Summary: Interact with the Neuronum Network to build, connect & automate economic data streams
5
5
  Home-page: https://neuronum.net
6
6
  Author: Neuronum Cybernetics
@@ -136,5 +136,12 @@ cell.stream(label, data)
136
136
  Sync stream:
137
137
  ```bash
138
138
  stream = cell.sync()
139
+ for operation in stream:
140
+ label = operation.get("label")
141
+ data = operation.get("data")
142
+ key = operation.get("data").get("key1")
143
+ time = operation.get("time")
144
+ stxID = operation.get("stxID")
145
+ operator = operation.get("cellHost")
139
146
  ```
140
147
 
@@ -0,0 +1,7 @@
1
+ neuronum/__init__.py,sha256=Drsm263_w3_VWgl1YsKLUr8WwVodqV3TSjqpxLjyq_M,46
2
+ neuronum/neuronum.py,sha256=UZw5oocfxTJslee0YB74_cWEre3JsyKLoCkh0Lpk3rs,7531
3
+ neuronum-1.2.4.dist-info/LICENSE,sha256=UiZjNHiCyRP6WoZfbYQh9cv4JW96wIofKXmzBJrYSUk,1125
4
+ neuronum-1.2.4.dist-info/METADATA,sha256=8If9GyeJyNYN7YCoFcunfazpFauyjxwfqqd08mKO1Pg,3676
5
+ neuronum-1.2.4.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
6
+ neuronum-1.2.4.dist-info/top_level.txt,sha256=73zXVVO9UTTiwEcSaXytsJ8n0q47OCwAqPlIh-hzWJU,9
7
+ neuronum-1.2.4.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- neuronum/__init__.py,sha256=Drsm263_w3_VWgl1YsKLUr8WwVodqV3TSjqpxLjyq_M,46
2
- neuronum/neuronum.py,sha256=Y0BMTTfBM3E9scEM57aDNj6wkwRH6yA0XwLj0nohodQ,7290
3
- neuronum-1.2.2.dist-info/LICENSE,sha256=UiZjNHiCyRP6WoZfbYQh9cv4JW96wIofKXmzBJrYSUk,1125
4
- neuronum-1.2.2.dist-info/METADATA,sha256=nHWQUddV45PHdXejJxwxgca6fhrWk_9OcVrKOnTRSss,3423
5
- neuronum-1.2.2.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
6
- neuronum-1.2.2.dist-info/top_level.txt,sha256=73zXVVO9UTTiwEcSaXytsJ8n0q47OCwAqPlIh-hzWJU,9
7
- neuronum-1.2.2.dist-info/RECORD,,