Spaces:
Build error
Build error
Update app.py
Browse files72 unmodified lines737475767778798081828384858687888990919293949510 unmodified lines106107108929394959697989910010110210310410911011111211311411511611711811972 unmodified lines """ return send_graphql_query(speckleToken, apiUrl, query)
def extract_team_name(object_data): # First try to get the team name directly data_field = object_data['data']['stream']['object']['data'] try: nested_data_str = data_field['data'] nested_data = json.loads(nested_data_str) return nested_data.get('teamName') except (KeyError, json.JSONDecodeError): pass
# If not found, check for referencedId if '@Data' in data_field: referenced_id = data_field['@Data'].get('referencedId') if referenced_id: return referenced_id # Returning the ID to fetch further if needed return None
@webhook_endpointasync def update_streams(request: Request): payload = await request.json()10 unmodified lines object_data = fetch_referenced_object(speckle_token, api_url, stream_id, referenced_object_id) if object_data: print(json.dumps(object_data, indent=2))
# Extract the 'data' field, which is a JSON string nested_data_str = object_data['data']['stream']['object']['data']['data']
# Parse the JSON string to a dictionary nested_data = json.loads(nested_data_str)
# Access the 'teamName' field team_name = nested_data.get('teamName', 'N/A') print(f"Team Name: {team_name}")
# Send the team name to the WebSocket server await send_data(team_name) team_name = extract_team_name(object_data) if team_name: print(f"Team Name: {team_name}") await send_data({"teamName": team_name}) else: print("Team name not found in the object data.") else: print("Failed to retrieve the referenced object data.") else:app.py+25-13