1- from specklepy .api .client import SpeckleClient
2- from specklepy .api .credentials import get_account_from_token
3- from specklepy .transports .server import ServerTransport
4- from specklepy .api import operations
5- from compas_cloud .speckle .data import Data as SpeckleData
1+ try :
2+ import specklepy
3+ from specklepy .api .client import SpeckleClient
4+ from specklepy .api .credentials import get_account_from_token
5+ from specklepy .transports .server import ServerTransport
6+ from specklepy .api import operations
7+ from compas_cloud .speckle .data import Data as SpeckleData
8+ except ImportError :
9+ specklepy = None
10+
611from compas .data import json_loads
712import json
813
@@ -20,20 +25,20 @@ def process_command(self, command):
2025 return "Command not found"
2126
2227 def connect (self , host = "speckle.xyz" , token = None ):
28+ if not specklepy :
29+ raise ImportError ("Specklepy is not installed" )
2330 print ("Connecting to {} with {}" .format (host , token ))
2431 self .client = SpeckleClient (host = host )
2532 account = get_account_from_token (token , host )
2633 self .client .authenticate_with_account (account )
27- return "Connected"
34+ return "Connected to {} with {}" . format ( host , token )
2835
2936 def update_item (self , item , stream_id = None , name = None , message = None ):
30- print ("CHECK!" , item )
31- print ("CHECK!" , stream_id )
3237 # Create new stream if stream_id is None
3338 if not stream_id :
3439 stream_id = self .client .stream .create (name = name )
3540 transport = ServerTransport (client = self .client , stream_id = stream_id )
36- hash = operations .send (base = SpeckleData (item ), transports = [transport ])
41+ hash = operations .send (base = SpeckleData (item , stream_id ), transports = [transport ])
3742 self .client .commit .create (
3843 stream_id = stream_id ,
3944 object_id = hash ,
@@ -49,9 +54,6 @@ def get_item(self, stream_id):
4954 data = received_base .data
5055 return json_loads (json .dumps (data ))
5156
52- # def watch_item(self, stream_id, callback):
53- # item = self.get_item(stream_id)
54- # callback(item)
5557
5658if __name__ == "__main__" :
5759
0 commit comments