apply ruff formatting

This commit is contained in:
Taylor Wilsdon
2025-12-13 13:49:28 -08:00
parent 1d80a24ca4
commit 6b8352a354
50 changed files with 4010 additions and 2842 deletions

View File

@@ -52,7 +52,10 @@ def _adjust_due_max_for_tasks_api(due_max: str) -> str:
try:
parsed = datetime.fromisoformat(due_max.replace("Z", "+00:00"))
except ValueError:
logger.warning("[list_tasks] Unable to parse due_max '%s'; sending unmodified value", due_max)
logger.warning(
"[list_tasks] Unable to parse due_max '%s'; sending unmodified value",
due_max,
)
return due_max
if parsed.tzinfo is None:
@@ -71,7 +74,7 @@ async def list_task_lists(
service: Resource,
user_google_email: str,
max_results: int = 1000,
page_token: Optional[str] = None
page_token: Optional[str] = None,
) -> str:
"""
List all task lists for the user.
@@ -93,9 +96,7 @@ async def list_task_lists(
if page_token:
params["pageToken"] = page_token
result = await asyncio.to_thread(
service.tasklists().list(**params).execute
)
result = await asyncio.to_thread(service.tasklists().list(**params).execute)
task_lists = result.get("items", [])
next_page_token = result.get("nextPageToken")
@@ -128,9 +129,7 @@ async def list_task_lists(
@require_google_service("tasks", "tasks_read") # type: ignore
@handle_http_errors("get_task_list", service_type="tasks") # type: ignore
async def get_task_list(
service: Resource,
user_google_email: str,
task_list_id: str
service: Resource, user_google_email: str, task_list_id: str
) -> str:
"""
Get details of a specific task list.
@@ -142,7 +141,9 @@ async def get_task_list(
Returns:
str: Task list details including title, ID, and last updated time.
"""
logger.info(f"[get_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}")
logger.info(
f"[get_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}"
)
try:
task_list = await asyncio.to_thread(
@@ -150,12 +151,14 @@ async def get_task_list(
)
response = f"""Task List Details for {user_google_email}:
- Title: {task_list['title']}
- ID: {task_list['id']}
- Updated: {task_list.get('updated', 'N/A')}
- Self Link: {task_list.get('selfLink', 'N/A')}"""
- Title: {task_list["title"]}
- ID: {task_list["id"]}
- Updated: {task_list.get("updated", "N/A")}
- Self Link: {task_list.get("selfLink", "N/A")}"""
logger.info(f"Retrieved task list '{task_list['title']}' for {user_google_email}")
logger.info(
f"Retrieved task list '{task_list['title']}' for {user_google_email}"
)
return response
except HttpError as error:
@@ -172,9 +175,7 @@ async def get_task_list(
@require_google_service("tasks", "tasks") # type: ignore
@handle_http_errors("create_task_list", service_type="tasks") # type: ignore
async def create_task_list(
service: Resource,
user_google_email: str,
title: str
service: Resource, user_google_email: str, title: str
) -> str:
"""
Create a new task list.
@@ -186,24 +187,24 @@ async def create_task_list(
Returns:
str: Confirmation message with the new task list ID and details.
"""
logger.info(f"[create_task_list] Invoked. Email: '{user_google_email}', Title: '{title}'")
logger.info(
f"[create_task_list] Invoked. Email: '{user_google_email}', Title: '{title}'"
)
try:
body = {
"title": title
}
body = {"title": title}
result = await asyncio.to_thread(
service.tasklists().insert(body=body).execute
)
result = await asyncio.to_thread(service.tasklists().insert(body=body).execute)
response = f"""Task List Created for {user_google_email}:
- Title: {result['title']}
- ID: {result['id']}
- Created: {result.get('updated', 'N/A')}
- Self Link: {result.get('selfLink', 'N/A')}"""
- Title: {result["title"]}
- ID: {result["id"]}
- Created: {result.get("updated", "N/A")}
- Self Link: {result.get("selfLink", "N/A")}"""
logger.info(f"Created task list '{title}' with ID {result['id']} for {user_google_email}")
logger.info(
f"Created task list '{title}' with ID {result['id']} for {user_google_email}"
)
return response
except HttpError as error:
@@ -220,10 +221,7 @@ async def create_task_list(
@require_google_service("tasks", "tasks") # type: ignore
@handle_http_errors("update_task_list", service_type="tasks") # type: ignore
async def update_task_list(
service: Resource,
user_google_email: str,
task_list_id: str,
title: str
service: Resource, user_google_email: str, task_list_id: str, title: str
) -> str:
"""
Update an existing task list.
@@ -236,24 +234,25 @@ async def update_task_list(
Returns:
str: Confirmation message with updated task list details.
"""
logger.info(f"[update_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, New Title: '{title}'")
logger.info(
f"[update_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, New Title: '{title}'"
)
try:
body = {
"id": task_list_id,
"title": title
}
body = {"id": task_list_id, "title": title}
result = await asyncio.to_thread(
service.tasklists().update(tasklist=task_list_id, body=body).execute
)
response = f"""Task List Updated for {user_google_email}:
- Title: {result['title']}
- ID: {result['id']}
- Updated: {result.get('updated', 'N/A')}"""
- Title: {result["title"]}
- ID: {result["id"]}
- Updated: {result.get("updated", "N/A")}"""
logger.info(f"Updated task list {task_list_id} with new title '{title}' for {user_google_email}")
logger.info(
f"Updated task list {task_list_id} with new title '{title}' for {user_google_email}"
)
return response
except HttpError as error:
@@ -270,9 +269,7 @@ async def update_task_list(
@require_google_service("tasks", "tasks") # type: ignore
@handle_http_errors("delete_task_list", service_type="tasks") # type: ignore
async def delete_task_list(
service: Resource,
user_google_email: str,
task_list_id: str
service: Resource, user_google_email: str, task_list_id: str
) -> str:
"""
Delete a task list. Note: This will also delete all tasks in the list.
@@ -284,7 +281,9 @@ async def delete_task_list(
Returns:
str: Confirmation message.
"""
logger.info(f"[delete_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}")
logger.info(
f"[delete_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}"
)
try:
await asyncio.to_thread(
@@ -346,7 +345,9 @@ async def list_tasks(
Returns:
str: List of tasks with their details.
"""
logger.info(f"[list_tasks] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}")
logger.info(
f"[list_tasks] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}"
)
try:
params: Dict[str, Any] = {"tasklist": task_list_id}
@@ -380,9 +381,7 @@ async def list_tasks(
if updated_min:
params["updatedMin"] = updated_min
result = await asyncio.to_thread(
service.tasks().list(**params).execute
)
result = await asyncio.to_thread(service.tasks().list(**params).execute)
tasks = result.get("items", [])
next_page_token = result.get("nextPageToken")
@@ -390,15 +389,15 @@ async def list_tasks(
# In order to return a sorted and organized list of tasks all at once, we support retrieving more than a single
# page from the Google tasks API.
results_remaining = (
min(max_results, LIST_TASKS_MAX_RESULTS_MAX) if max_results else LIST_TASKS_MAX_RESULTS_DEFAULT
min(max_results, LIST_TASKS_MAX_RESULTS_MAX)
if max_results
else LIST_TASKS_MAX_RESULTS_DEFAULT
)
results_remaining -= len(tasks)
while results_remaining > 0 and next_page_token:
params["pageToken"] = next_page_token
params["maxResults"] = str(results_remaining)
result = await asyncio.to_thread(
service.tasks().list(**params).execute
)
result = await asyncio.to_thread(service.tasks().list(**params).execute)
more_tasks = result.get("items", [])
next_page_token = result.get("nextPageToken")
if len(more_tasks) == 0:
@@ -408,7 +407,9 @@ async def list_tasks(
results_remaining -= len(more_tasks)
if not tasks:
return f"No tasks found in task list {task_list_id} for {user_google_email}."
return (
f"No tasks found in task list {task_list_id} for {user_google_email}."
)
structured_tasks = get_structured_tasks(tasks)
@@ -418,7 +419,9 @@ async def list_tasks(
if next_page_token:
response += f"Next page token: {next_page_token}\n"
logger.info(f"Found {len(tasks)} tasks in list {task_list_id} for {user_google_email}")
logger.info(
f"Found {len(tasks)} tasks in list {task_list_id} for {user_google_email}"
)
return response
except HttpError as error:
@@ -550,10 +553,7 @@ This can also occur due to filtering that excludes parent tasks while including
@require_google_service("tasks", "tasks_read") # type: ignore
@handle_http_errors("get_task", service_type="tasks") # type: ignore
async def get_task(
service: Resource,
user_google_email: str,
task_list_id: str,
task_id: str
service: Resource, user_google_email: str, task_list_id: str, task_id: str
) -> str:
"""
Get details of a specific task.
@@ -566,7 +566,9 @@ async def get_task(
Returns:
str: Task details including title, notes, status, due date, etc.
"""
logger.info(f"[get_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}")
logger.info(
f"[get_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}"
)
try:
task = await asyncio.to_thread(
@@ -574,27 +576,29 @@ async def get_task(
)
response = f"""Task Details for {user_google_email}:
- Title: {task.get('title', 'Untitled')}
- ID: {task['id']}
- Status: {task.get('status', 'N/A')}
- Updated: {task.get('updated', 'N/A')}"""
- Title: {task.get("title", "Untitled")}
- ID: {task["id"]}
- Status: {task.get("status", "N/A")}
- Updated: {task.get("updated", "N/A")}"""
if task.get('due'):
if task.get("due"):
response += f"\n- Due Date: {task['due']}"
if task.get('completed'):
if task.get("completed"):
response += f"\n- Completed: {task['completed']}"
if task.get('notes'):
if task.get("notes"):
response += f"\n- Notes: {task['notes']}"
if task.get('parent'):
if task.get("parent"):
response += f"\n- Parent Task ID: {task['parent']}"
if task.get('position'):
if task.get("position"):
response += f"\n- Position: {task['position']}"
if task.get('selfLink'):
if task.get("selfLink"):
response += f"\n- Self Link: {task['selfLink']}"
if task.get('webViewLink'):
if task.get("webViewLink"):
response += f"\n- Web View Link: {task['webViewLink']}"
logger.info(f"Retrieved task '{task.get('title', 'Untitled')}' for {user_google_email}")
logger.info(
f"Retrieved task '{task.get('title', 'Untitled')}' for {user_google_email}"
)
return response
except HttpError as error:
@@ -618,7 +622,7 @@ async def create_task(
notes: Optional[str] = None,
due: Optional[str] = None,
parent: Optional[str] = None,
previous: Optional[str] = None
previous: Optional[str] = None,
) -> str:
"""
Create a new task in a task list.
@@ -635,12 +639,12 @@ async def create_task(
Returns:
str: Confirmation message with the new task ID and details.
"""
logger.info(f"[create_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Title: '{title}'")
logger.info(
f"[create_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Title: '{title}'"
)
try:
body = {
"title": title
}
body = {"title": title}
if notes:
body["notes"] = notes
if due:
@@ -652,24 +656,24 @@ async def create_task(
if previous:
params["previous"] = previous
result = await asyncio.to_thread(
service.tasks().insert(**params).execute
)
result = await asyncio.to_thread(service.tasks().insert(**params).execute)
response = f"""Task Created for {user_google_email}:
- Title: {result['title']}
- ID: {result['id']}
- Status: {result.get('status', 'N/A')}
- Updated: {result.get('updated', 'N/A')}"""
- Title: {result["title"]}
- ID: {result["id"]}
- Status: {result.get("status", "N/A")}
- Updated: {result.get("updated", "N/A")}"""
if result.get('due'):
if result.get("due"):
response += f"\n- Due Date: {result['due']}"
if result.get('notes'):
if result.get("notes"):
response += f"\n- Notes: {result['notes']}"
if result.get('webViewLink'):
if result.get("webViewLink"):
response += f"\n- Web View Link: {result['webViewLink']}"
logger.info(f"Created task '{title}' with ID {result['id']} for {user_google_email}")
logger.info(
f"Created task '{title}' with ID {result['id']} for {user_google_email}"
)
return response
except HttpError as error:
@@ -693,7 +697,7 @@ async def update_task(
title: Optional[str] = None,
notes: Optional[str] = None,
status: Optional[str] = None,
due: Optional[str] = None
due: Optional[str] = None,
) -> str:
"""
Update an existing task.
@@ -710,7 +714,9 @@ async def update_task(
Returns:
str: Confirmation message with updated task details.
"""
logger.info(f"[update_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}")
logger.info(
f"[update_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}"
)
try:
# First get the current task to build the update body
@@ -721,7 +727,9 @@ async def update_task(
body = {
"id": task_id,
"title": title if title is not None else current_task.get("title", ""),
"status": status if status is not None else current_task.get("status", "needsAction")
"status": status
if status is not None
else current_task.get("status", "needsAction"),
}
if notes is not None:
@@ -735,20 +743,22 @@ async def update_task(
body["due"] = current_task["due"]
result = await asyncio.to_thread(
service.tasks().update(tasklist=task_list_id, task=task_id, body=body).execute
service.tasks()
.update(tasklist=task_list_id, task=task_id, body=body)
.execute
)
response = f"""Task Updated for {user_google_email}:
- Title: {result['title']}
- ID: {result['id']}
- Status: {result.get('status', 'N/A')}
- Updated: {result.get('updated', 'N/A')}"""
- Title: {result["title"]}
- ID: {result["id"]}
- Status: {result.get("status", "N/A")}
- Updated: {result.get("updated", "N/A")}"""
if result.get('due'):
if result.get("due"):
response += f"\n- Due Date: {result['due']}"
if result.get('notes'):
if result.get("notes"):
response += f"\n- Notes: {result['notes']}"
if result.get('completed'):
if result.get("completed"):
response += f"\n- Completed: {result['completed']}"
logger.info(f"Updated task {task_id} for {user_google_email}")
@@ -768,10 +778,7 @@ async def update_task(
@require_google_service("tasks", "tasks") # type: ignore
@handle_http_errors("delete_task", service_type="tasks") # type: ignore
async def delete_task(
service: Resource,
user_google_email: str,
task_list_id: str,
task_id: str
service: Resource, user_google_email: str, task_list_id: str, task_id: str
) -> str:
"""
Delete a task from a task list.
@@ -784,7 +791,9 @@ async def delete_task(
Returns:
str: Confirmation message.
"""
logger.info(f"[delete_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}")
logger.info(
f"[delete_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}"
)
try:
await asyncio.to_thread(
@@ -816,7 +825,7 @@ async def move_task(
task_id: str,
parent: Optional[str] = None,
previous: Optional[str] = None,
destination_task_list: Optional[str] = None
destination_task_list: Optional[str] = None,
) -> str:
"""
Move a task to a different position or parent within the same list, or to a different list.
@@ -832,13 +841,12 @@ async def move_task(
Returns:
str: Confirmation message with updated task details.
"""
logger.info(f"[move_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}")
logger.info(
f"[move_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}"
)
try:
params = {
"tasklist": task_list_id,
"task": task_id
}
params = {"tasklist": task_list_id, "task": task_id}
if parent:
params["parent"] = parent
if previous:
@@ -846,19 +854,17 @@ async def move_task(
if destination_task_list:
params["destinationTasklist"] = destination_task_list
result = await asyncio.to_thread(
service.tasks().move(**params).execute
)
result = await asyncio.to_thread(service.tasks().move(**params).execute)
response = f"""Task Moved for {user_google_email}:
- Title: {result['title']}
- ID: {result['id']}
- Status: {result.get('status', 'N/A')}
- Updated: {result.get('updated', 'N/A')}"""
- Title: {result["title"]}
- ID: {result["id"]}
- Status: {result.get("status", "N/A")}
- Updated: {result.get("updated", "N/A")}"""
if result.get('parent'):
if result.get("parent"):
response += f"\n- Parent Task ID: {result['parent']}"
if result.get('position'):
if result.get("position"):
response += f"\n- Position: {result['position']}"
move_details = []
@@ -889,9 +895,7 @@ async def move_task(
@require_google_service("tasks", "tasks") # type: ignore
@handle_http_errors("clear_completed_tasks", service_type="tasks") # type: ignore
async def clear_completed_tasks(
service: Resource,
user_google_email: str,
task_list_id: str
service: Resource, user_google_email: str, task_list_id: str
) -> str:
"""
Clear all completed tasks from a task list. The tasks will be marked as hidden.
@@ -903,16 +907,18 @@ async def clear_completed_tasks(
Returns:
str: Confirmation message.
"""
logger.info(f"[clear_completed_tasks] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}")
logger.info(
f"[clear_completed_tasks] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}"
)
try:
await asyncio.to_thread(
service.tasks().clear(tasklist=task_list_id).execute
)
await asyncio.to_thread(service.tasks().clear(tasklist=task_list_id).execute)
response = f"All completed tasks have been cleared from task list {task_list_id} for {user_google_email}. The tasks are now hidden and won't appear in default task list views."
logger.info(f"Cleared completed tasks from list {task_list_id} for {user_google_email}")
logger.info(
f"Cleared completed tasks from list {task_list_id} for {user_google_email}"
)
return response
except HttpError as error: