serJD commited on
Commit
6fcd547
·
1 Parent(s): 7a88829

added logic to update only stream the webhook was sent front

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -219,7 +219,7 @@ async def update_streams(request: Request):
219
  payload = await request.json()
220
 
221
  print(str(payload))
222
-
223
 
224
  # Accessing nested data in the 'event' object
225
 
@@ -229,12 +229,26 @@ async def update_streams(request: Request):
229
  #client = SpeckleClient(host="https://speckle.xyz")
230
  #client.authenticate_with_token(token=speckle_token)
231
 
232
- for key, value in streams.items():
233
- stream_id = value["stream"]
234
- notion_db = value["notionDB"]
235
 
236
- branch_data = extract_branch_info(stream_id, server_url="https://speckle.xyz/", token=speckle_token)
237
- sync_to_notion(notion_token, notion_db, branch_data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
 
239
  return "All streams updated successfully!"
240
 
 
219
  payload = await request.json()
220
 
221
  print(str(payload))
222
+
223
 
224
  # Accessing nested data in the 'event' object
225
 
 
229
  #client = SpeckleClient(host="https://speckle.xyz")
230
  #client.authenticate_with_token(token=speckle_token)
231
 
 
 
 
232
 
233
+
234
+ if 'payload' in payload and 'stream' in payload['payload']:
235
+ stream_info = payload['payload']['stream']
236
+ if 'name' in stream_info:
237
+ stream_name = stream_info['name']
238
+ print("update dat for: " + stream_name)
239
+ # retrieve specific stream
240
+ stream_id = streams[stream_name]["stream"]
241
+ notion_db = streams[stream_name]["notionDB"]
242
+ branch_data = extract_branch_info(stream_id, server_url="https://speckle.xyz/", token=speckle_token)
243
+ sync_to_notion(notion_token, notion_db, branch_data)
244
+ else:
245
+ print("updating data for all streams")
246
+ for key, value in streams.items():
247
+ stream_id = value["stream"]
248
+ notion_db = value["notionDB"]
249
+
250
+ branch_data = extract_branch_info(stream_id, server_url="https://speckle.xyz/", token=speckle_token)
251
+ sync_to_notion(notion_token, notion_db, branch_data)
252
 
253
  return "All streams updated successfully!"
254