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