Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,119 +36,55 @@ ASANA_HEADERS = {
|
|
| 36 |
|
| 37 |
DEFAULT_PROJECT_GID = "1209104858113361"
|
| 38 |
|
| 39 |
-
''''
|
| 40 |
-
|
| 41 |
def create_asana_task(name, due_date=None):
|
| 42 |
"""Create a task in Asana."""
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
tasks_api = asana.TasksApi(api_client)
|
| 49 |
-
|
| 50 |
-
url = f"{ASANA_BASE_URL}/tasks" # Construct the URL for creating tasks
|
| 51 |
-
data = {
|
| 52 |
-
"data": {
|
| 53 |
-
"name": name,
|
| 54 |
-
"projects": [DEFAULT_PROJECT_GID]
|
| 55 |
-
}
|
| 56 |
-
}
|
| 57 |
-
if due_date:
|
| 58 |
-
data["data"]["due_on"] = due_date # Asana uses 'due_on' in YYYY-MM-DD format
|
| 59 |
-
|
| 60 |
-
# Create the task using the requests library
|
| 61 |
-
headers = {
|
| 62 |
-
'Authorization': f'Bearer {access_token}',
|
| 63 |
-
'Content-Type': 'application/json',
|
| 64 |
}
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
print(f"Exception when creating task: {e}\n")
|
| 74 |
-
return {"error": str(e)}
|
| 75 |
-
finally:
|
| 76 |
-
if api_client:
|
| 77 |
-
api_client.close()
|
| 78 |
|
| 79 |
def list_asana_tasks(only_open=True):
|
| 80 |
"""List tasks in the default project, optionally filtering for only open tasks."""
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
response = requests.get(url, headers=headers, params=params)
|
| 100 |
-
|
| 101 |
-
if response.status_code == 200:
|
| 102 |
-
tasks = response.json()["data"]
|
| 103 |
-
if only_open:
|
| 104 |
-
tasks = [task for task in tasks if not task.get("completed", False)]
|
| 105 |
-
return tasks
|
| 106 |
-
else:
|
| 107 |
-
return {"error": response.text}
|
| 108 |
-
|
| 109 |
-
except Exception as e:
|
| 110 |
-
print(f"Exception when listing tasks: {e}\n")
|
| 111 |
-
return {"error": str(e)}
|
| 112 |
-
finally:
|
| 113 |
-
if api_client:
|
| 114 |
-
api_client.close()
|
| 115 |
|
| 116 |
def complete_asana_task(task_gid):
|
| 117 |
"""Mark a task as complete."""
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
api_client = asana.ApiClient(configuration)
|
| 123 |
-
tasks_api = asana.TasksApi(api_client)
|
| 124 |
-
|
| 125 |
-
url = f"{ASANA_BASE_URL}/tasks/{task_gid}"
|
| 126 |
-
data = {
|
| 127 |
-
"data": {
|
| 128 |
-
"completed": True
|
| 129 |
-
}
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
headers = {
|
| 133 |
-
'Authorization': f'Bearer {access_token}',
|
| 134 |
-
'Content-Type': 'application/json',
|
| 135 |
}
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
return {"error": response.text}
|
| 143 |
-
|
| 144 |
-
except Exception as e:
|
| 145 |
-
print(f"Exception when completing task: {e}\n")
|
| 146 |
-
return {"error": str(e)}
|
| 147 |
-
finally:
|
| 148 |
-
if api_client:
|
| 149 |
-
api_client.close()
|
| 150 |
-
|
| 151 |
-
'''
|
| 152 |
|
| 153 |
def call_llm(user_message, conversation_history=None):
|
| 154 |
today_date = datetime.date.today().strftime("%Y-%m-%d")
|
|
|
|
| 36 |
|
| 37 |
DEFAULT_PROJECT_GID = "1209104858113361"
|
| 38 |
|
|
|
|
|
|
|
| 39 |
def create_asana_task(name, due_date=None):
|
| 40 |
"""Create a task in Asana."""
|
| 41 |
+
url = f"{ASANA_BASE_URL}/tasks"
|
| 42 |
+
data = {
|
| 43 |
+
"data": {
|
| 44 |
+
"name": name,
|
| 45 |
+
"projects": [DEFAULT_PROJECT_GID]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
+
}
|
| 48 |
+
if due_date:
|
| 49 |
+
data["data"]["due_on"] = due_date # Asana uses 'due_on' in YYYY-MM-DD format
|
| 50 |
+
resp = requests.post(url, json=data, headers=ASANA_HEADERS)
|
| 51 |
+
if resp.status_code == 201:
|
| 52 |
+
return resp.json()["data"] # returns the newly created task object
|
| 53 |
+
else:
|
| 54 |
+
return {"error": resp.text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
def list_asana_tasks(only_open=True):
|
| 57 |
"""List tasks in the default project, optionally filtering for only open tasks."""
|
| 58 |
+
url = f"{ASANA_BASE_URL}/projects/{DEFAULT_PROJECT_GID}/tasks"
|
| 59 |
+
params = {
|
| 60 |
+
"opt_fields": "name,completed" # Include the "completed" field to verify task status
|
| 61 |
+
}
|
| 62 |
+
if only_open:
|
| 63 |
+
params["completed_since"] = "now" # Fetch only incomplete or recently updated tasks
|
| 64 |
+
|
| 65 |
+
resp = requests.get(url, headers=ASANA_HEADERS, params=params)
|
| 66 |
+
if resp.status_code == 200:
|
| 67 |
+
tasks = resp.json()["data"]
|
| 68 |
+
if only_open:
|
| 69 |
+
# Filter out completed tasks if only_open is True
|
| 70 |
+
tasks = [task for task in tasks if not task.get("completed", False)]
|
| 71 |
+
return tasks
|
| 72 |
+
else:
|
| 73 |
+
return {"error": resp.text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
def complete_asana_task(task_gid):
|
| 76 |
"""Mark a task as complete."""
|
| 77 |
+
url = f"{ASANA_BASE_URL}/tasks/{task_gid}"
|
| 78 |
+
data = {
|
| 79 |
+
"data": {
|
| 80 |
+
"completed": True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
}
|
| 82 |
+
}
|
| 83 |
+
resp = requests.put(url, json=data, headers=ASANA_HEADERS)
|
| 84 |
+
if resp.status_code == 200:
|
| 85 |
+
return resp.json()["data"]
|
| 86 |
+
else:
|
| 87 |
+
return {"error": resp.text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
def call_llm(user_message, conversation_history=None):
|
| 90 |
today_date = datetime.date.today().strftime("%Y-%m-%d")
|