diff --git a/main.py b/main.py index 26339b6..be4d5e2 100644 --- a/main.py +++ b/main.py @@ -149,6 +149,49 @@ def pick_uid(obj: Dict[str, Any]) -> Optional[str]: s = str(v).strip() return s or None +def todoist_task_url(task: Dict[str, Any]) -> str: + """ + Best-effort URL to the Todoist task. + - If Todoist provides a direct url field, use it. + - Otherwise fall back to the canonical web UI endpoint. + """ + # sometimes present in some payloads (completed/rest) + url = task.get("url") or task.get("task_url") or task.get("taskUrl") + if isinstance(url, str) and url.strip(): + return url.strip() + + tid = task.get("id") + if tid is None: + return "https://todoist.com/" + return f"https://todoist.com/showTask?id={tid}" + + +def build_tududi_description_from_todoist(task: Dict[str, Any], task_name: str) -> str: + """ + Tududi description format: + + + + [Todoist task](...) + + + """ + parts: List[str] = [] + + # Task name (explicit, even if Tududi already has it) + parts.append(task_name.strip()) + + # Todoist link + tid = task.get("id") + if tid: + parts.append(f"\n[Todoist task](https://todoist.com/showTask?id={tid})") + + # Todoist description + td_desc = task.get("description") + if isinstance(td_desc, str) and td_desc.strip(): + parts.append("\n" + td_desc.strip()) + + return "\n\n".join(parts).strip() # ---------------------------- # Todoist client (API v1) @@ -848,6 +891,9 @@ def main() -> None: project_uid = get_project_uid_for_task(task) tags = get_tags_for_task(task) + # Tududi note: Todoist link + Todoist description + tududi_description = build_tududi_description_from_todoist(task, name) + desc = task.get("description") or "" comments = comments_idx.get(tid, []) desc_extra = comments_to_text(comments) @@ -863,7 +909,8 @@ def main() -> None: due_date=due, priority=prio, tags=tags if tags else None, - description=desc if desc else None, + description=tududi_description, + note=tududi_description, parent_task_id=tud_parent_id, is_completed=is_completed if is_completed else None, completed_at=completed_at,