22from specklepy .api .credentials import get_account_from_token
33from specklepy .transports .server import ServerTransport
44from specklepy .api import operations
5- from data import Data as SpeckleData
5+ from compas_cloud . speckle . data import Data as SpeckleData
66from compas .data import json_loads
77import json
88
99
1010class Speckle ():
11- def __init__ (self , host = "speckle.xyz" , token = None ):
11+
12+ def process_command (self , command ):
13+ if 'connect' in command :
14+ return self .connect (host = command ['connect' ]['host' ], token = command ['connect' ]['token' ])
15+ if 'get' in command :
16+ return self .get_item (command ['get' ]['stream_id' ])
17+ if 'update' in command :
18+ return self .update_item (command ['update' ]['item' ], stream_id = command ['update' ]['stream_id' ])
19+ else :
20+ return "Command not found"
21+
22+ def connect (self , host = "speckle.xyz" , token = None ):
23+ print ("Connecting to {} with {}" .format (host , token ))
1224 self .client = SpeckleClient (host = host )
1325 account = get_account_from_token (token , host )
1426 self .client .authenticate_with_account (account )
27+ return "Connected"
1528
1629 def update_item (self , item , stream_id = None , name = None , message = None ):
30+ print ("CHECK!" , item )
31+ print ("CHECK!" , stream_id )
1732 # Create new stream if stream_id is None
1833 if not stream_id :
1934 stream_id = self .client .stream .create (name = name )
@@ -34,19 +49,23 @@ def get_item(self, stream_id):
3449 data = received_base .data
3550 return json_loads (json .dumps (data ))
3651
52+ # def watch_item(self, stream_id, callback):
53+ # item = self.get_item(stream_id)
54+ # callback(item)
3755
3856if __name__ == "__main__" :
3957
4058 import compas
4159 from compas .datastructures import Mesh
4260
43- client = Speckle (token = "5da18a1e41f477bf4d70bce651b151aa6e14d5cc8d" )
61+ client = Speckle ()
62+ client .connect (token = "4b6a06f4c7b114e3b4115e1bba5536261cb4d3bf20" )
4463
4564 stream_id = "c0538fd521"
46- # mesh = Mesh.from_obj(compas.get('faces.obj'))
47- # stream_id = client.update_item(mesh, name="faces", stream_id=stream_id)
48- # print(stream_id)
65+ mesh = Mesh .from_obj (compas .get ('faces.obj' ))
66+ stream_id = client .update_item (mesh , name = "faces" , stream_id = stream_id )
67+ print (stream_id )
4968
5069 # stream_id = "c0538fd521"
51- item = client .get_item (stream_id )
52- print (item )
70+ # item = client.get_item(stream_id)
71+ # print(item)
0 commit comments