Spaces:
Sleeping
Sleeping
added multi-select option
Browse files
app.py
CHANGED
|
@@ -72,6 +72,18 @@ def extract_branch_info(stream_id, server_url=None, token=None):
|
|
| 72 |
return branch_info
|
| 73 |
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
def sync_to_notion(token, database_id, branch_data):
|
| 77 |
base_url = "https://api.notion.com/v1"
|
|
@@ -82,6 +94,12 @@ def sync_to_notion(token, database_id, branch_data):
|
|
| 82 |
}
|
| 83 |
|
| 84 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
# Fetch existing data from Notion database
|
| 86 |
response = requests.post(f"{base_url}/databases/{database_id}/query", headers=headers)
|
| 87 |
response.raise_for_status()
|
|
|
|
| 72 |
return branch_info
|
| 73 |
|
| 74 |
|
| 75 |
+
def update_select_options(database_id, headers, branch_names):
|
| 76 |
+
update_payload = {
|
| 77 |
+
"properties": {
|
| 78 |
+
"depends-on": {
|
| 79 |
+
"multi_select": {
|
| 80 |
+
"options": [{"name": name} for name in branch_names]
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
response = requests.patch(f"https://api.notion.com/v1/databases/{database_id}", headers=headers, json=update_payload)
|
| 86 |
+
response.raise_for_status()
|
| 87 |
|
| 88 |
def sync_to_notion(token, database_id, branch_data):
|
| 89 |
base_url = "https://api.notion.com/v1"
|
|
|
|
| 94 |
}
|
| 95 |
|
| 96 |
try:
|
| 97 |
+
|
| 98 |
+
# Extract all branch names for the "depends-on" options
|
| 99 |
+
branch_names = [branch['Name'] for branch in branch_data]
|
| 100 |
+
# Update the "depends-on" multi-select options to match branch names
|
| 101 |
+
update_select_options(database_id, headers, branch_names)
|
| 102 |
+
|
| 103 |
# Fetch existing data from Notion database
|
| 104 |
response = requests.post(f"{base_url}/databases/{database_id}/query", headers=headers)
|
| 105 |
response.raise_for_status()
|