Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -369,10 +369,90 @@ def handle_calendar_integration(access_token):
|
|
369 |
else:
|
370 |
st.error("Failed to delete event.")
|
371 |
|
|
|
|
|
372 |
def handle_tasks_integration(access_token):
|
373 |
st.subheader("π Tasks Integration")
|
374 |
st.markdown(f"[Open Tasks]({PRODUCT_SCOPES['π Tasks']['link']})")
|
375 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
# Read tasks
|
377 |
tasks = make_api_call(access_token, 'me/todo/lists')
|
378 |
if tasks and 'value' in tasks:
|
|
|
369 |
else:
|
370 |
st.error("Failed to delete event.")
|
371 |
|
372 |
+
|
373 |
+
|
374 |
def handle_tasks_integration(access_token):
|
375 |
st.subheader("π Tasks Integration")
|
376 |
st.markdown(f"[Open Tasks]({PRODUCT_SCOPES['π Tasks']['link']})")
|
377 |
|
378 |
+
# Read tasks
|
379 |
+
tasks = make_api_call(access_token, 'me/todo/lists')
|
380 |
+
|
381 |
+
if tasks and 'value' in tasks:
|
382 |
+
default_list = next((list for list in tasks['value'] if list['wellknownListName'] == 'defaultList'), None)
|
383 |
+
if default_list:
|
384 |
+
tasks = make_api_call(access_token, f"me/todo/lists/{default_list['id']}/tasks")
|
385 |
+
if tasks and 'value' in tasks:
|
386 |
+
# Convert task data into a format suitable for a dataframe
|
387 |
+
task_data = [
|
388 |
+
{"Task": task['title'], "Status": "Completed" if task['status'] == 'completed' else "Not Completed"}
|
389 |
+
for task in tasks['value']
|
390 |
+
]
|
391 |
+
|
392 |
+
# Create a dataframe from the task data
|
393 |
+
import pandas as pd
|
394 |
+
df = pd.DataFrame(task_data)
|
395 |
+
|
396 |
+
# Add a search box for filtering tasks
|
397 |
+
search_query = st.text_input("π Search Tasks", "")
|
398 |
+
if search_query:
|
399 |
+
df = df[df['Task'].str.contains(search_query, case=False, na=False)]
|
400 |
+
|
401 |
+
# Display the dataframe with filtered tasks
|
402 |
+
st.dataframe(df)
|
403 |
+
|
404 |
+
st.write("---")
|
405 |
+
else:
|
406 |
+
st.write("No tasks found or unable to fetch tasks.")
|
407 |
+
else:
|
408 |
+
st.write("Default task list not found.")
|
409 |
+
else:
|
410 |
+
st.write("Unable to fetch task lists.")
|
411 |
+
|
412 |
+
# Create task
|
413 |
+
st.write("Add a new task:")
|
414 |
+
task_title = st.text_input("Task Title")
|
415 |
+
if st.button("Add Task"):
|
416 |
+
new_task = {
|
417 |
+
"title": task_title
|
418 |
+
}
|
419 |
+
result = make_api_call(access_token, f"me/todo/lists/{default_list['id']}/tasks", method='POST', data=new_task)
|
420 |
+
if result:
|
421 |
+
st.success("Task added successfully!")
|
422 |
+
else:
|
423 |
+
st.error("Failed to add task.")
|
424 |
+
|
425 |
+
# Update task
|
426 |
+
st.write("Update a task:")
|
427 |
+
task_id = st.text_input("Enter Task ID")
|
428 |
+
new_title = st.text_input("New Title")
|
429 |
+
if st.button("Update Task"):
|
430 |
+
update_data = {
|
431 |
+
"title": new_title
|
432 |
+
}
|
433 |
+
result = make_api_call(access_token, f"me/todo/lists/{default_list['id']}/tasks/{task_id}", method='PATCH', data=update_data)
|
434 |
+
if result is None: # PATCH doesn't return content on success
|
435 |
+
st.success("Task updated successfully!")
|
436 |
+
else:
|
437 |
+
st.error("Failed to update task.")
|
438 |
+
|
439 |
+
# Delete task
|
440 |
+
st.write("Delete a task:")
|
441 |
+
task_id_to_delete = st.text_input("Enter Task ID to delete")
|
442 |
+
if st.button("Delete Task"):
|
443 |
+
result = make_api_call(access_token, f"me/todo/lists/{default_list['id']}/tasks/{task_id_to_delete}", method='DELETE')
|
444 |
+
if result is None: # DELETE doesn't return content on success
|
445 |
+
st.success("Task deleted successfully!")
|
446 |
+
else:
|
447 |
+
st.error("Failed to delete task.")
|
448 |
+
|
449 |
+
|
450 |
+
|
451 |
+
|
452 |
+
def handle_tasks_integration_old(access_token):
|
453 |
+
st.subheader("π Tasks Integration")
|
454 |
+
st.markdown(f"[Open Tasks]({PRODUCT_SCOPES['π Tasks']['link']})")
|
455 |
+
|
456 |
# Read tasks
|
457 |
tasks = make_api_call(access_token, 'me/todo/lists')
|
458 |
if tasks and 'value' in tasks:
|