Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -248,13 +248,13 @@ def reset_database(notion, database_id):
|
|
| 248 |
|
| 249 |
# Function to run on button click
|
| 250 |
@webhook_endpoint # Define a unique endpoint URL
|
| 251 |
-
async def
|
| 252 |
# Read the request body as JSON
|
| 253 |
payload = await request.json()
|
| 254 |
|
| 255 |
print(str(payload))
|
| 256 |
|
| 257 |
-
|
| 258 |
# Accessing nested data in the 'event' object
|
| 259 |
|
| 260 |
speckle_token = os.environ.get("SPECKLE_TOKEN")
|
|
@@ -273,69 +273,69 @@ async def update_streams(request: Request):
|
|
| 273 |
|
| 274 |
|
| 275 |
# Iterate through the results (each page corresponds to a row in the database)
|
| 276 |
-
for page in database_pages:
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
-
|
|
|
|
| 248 |
|
| 249 |
# Function to run on button click
|
| 250 |
@webhook_endpoint # Define a unique endpoint URL
|
| 251 |
+
async def update_table(request: Request):
|
| 252 |
# Read the request body as JSON
|
| 253 |
payload = await request.json()
|
| 254 |
|
| 255 |
print(str(payload))
|
| 256 |
|
| 257 |
+
continueFlag = True
|
| 258 |
# Accessing nested data in the 'event' object
|
| 259 |
|
| 260 |
speckle_token = os.environ.get("SPECKLE_TOKEN")
|
|
|
|
| 273 |
|
| 274 |
|
| 275 |
# Iterate through the results (each page corresponds to a row in the database)
|
| 276 |
+
for page in database_pages:
|
| 277 |
+
|
| 278 |
+
#check speckleAnalysisName
|
| 279 |
+
speckName = get_property_value(page, "speckleName")
|
| 280 |
+
shortName = get_property_value(page, "nameShort")
|
| 281 |
+
longName = get_property_value(page, "nameLong")
|
| 282 |
+
print(shortName)
|
| 283 |
+
print(longName)
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
subAttributes = get_property_value(page, "level_4")
|
| 287 |
+
|
| 288 |
+
subAttributeFlag = False
|
| 289 |
+
if len(subAttributes)>1:
|
| 290 |
+
if subAttributes[0] != 'NA':
|
| 291 |
+
subAttributeFlag = True
|
| 292 |
+
for subAttr in subAttributes:
|
| 293 |
+
# construct new page (speckleName, Name, longName, shortName, remove level_4)
|
| 294 |
+
new_page = copy.deepcopy(page)
|
| 295 |
+
speckName_full = speckName+subAttr
|
| 296 |
+
if "#+" in shortName:
|
| 297 |
+
shortestName = name_mapper.get(subAttr,subAttr)
|
| 298 |
+
mediumName = name_mapperM.get(subAttr,subAttr)
|
| 299 |
+
print("shortestName", shortestName, subAttr)
|
| 300 |
+
shortName_full = shortName.replace("#+", shortestName)
|
| 301 |
+
shortName_full.replace("DRT", "ART")
|
| 302 |
+
#update short name
|
| 303 |
+
replace_property_value(new_page, "nameShort", shortName_full )
|
| 304 |
+
|
| 305 |
+
if "#+" in longName:
|
| 306 |
+
longName_full = longName.replace("#+", "::" +mediumName)
|
| 307 |
+
longName_full = longName_full.replace(" ::", "::")
|
| 308 |
+
longName_full = longName_full.replace(":: ", "::")
|
| 309 |
+
longName_full.replace("DRT", "ART")
|
| 310 |
+
#update long name
|
| 311 |
+
replace_property_value(new_page, "nameLong", longName_full )
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
#update speckle name (-> as title column)
|
| 316 |
+
replace_property_value(new_page, "name", speckName_full)
|
| 317 |
+
# remove level_4 and speckleAnalysisName
|
| 318 |
+
new_page = remove_property(new_page, "level_4")
|
| 319 |
+
new_page = remove_property(new_page, "speckleName")
|
| 320 |
+
new_page = remove_property(new_page, "Items")
|
| 321 |
+
|
| 322 |
+
# update target database in notion
|
| 323 |
+
check_and_update_or_create_page(notion, new_page, target_db, "name")
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
if subAttributeFlag == False:
|
| 328 |
+
# forward page
|
| 329 |
+
new_page = copy.deepcopy(page)
|
| 330 |
+
replace_property_value(new_page, "name", speckName)
|
| 331 |
+
new_page = remove_property(new_page, "level_4")
|
| 332 |
+
new_page = remove_property(new_page, "speckleName")
|
| 333 |
+
new_page = remove_property(new_page, "Items")
|
| 334 |
+
|
| 335 |
+
# update target database in notion
|
| 336 |
+
print(get_property_value(new_page, "nameLong"))
|
| 337 |
+
check_and_update_or_create_page(notion, new_page, target_db, "name")
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
+
return "All streams updated successfully!"
|