From 1630d2824127d7557eacb866557ae95415954fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Bu=C3=9Fmann?= Date: Wed, 21 Feb 2024 03:04:06 +0100 Subject: [PATCH] Proof of Concept --- .gitignore | 2 ++ things2reclaim.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 things2reclaim.py diff --git a/.gitignore b/.gitignore index 68bc17f..a4a0b19 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +.reclaim.toml diff --git a/things2reclaim.py b/things2reclaim.py new file mode 100755 index 0000000..e3919ef --- /dev/null +++ b/things2reclaim.py @@ -0,0 +1,49 @@ +#!/opt/homebrew/Caskroom/miniconda/base/envs/things-automation/bin/python3 + +import things +from reclaim_sdk.models.task import ReclaimTask +from datetime import datetime + + +def extract_uni_projects(): + uni_area = next(area for area in things.areas() if area["title"] == "Uni") + return things.projects(area=uni_area["uuid"]) + + +def get_tasks_for_project(project): + return things.tasks(project=project["uuid"], type="to-do") + + +def things_to_reclaim(things_task, project_title): + with ReclaimTask() as reclaim_task: + reclaim_task.name = "{} {}".format(project_title, things_task["title"]) + reclaim_task.start_date = datetime.strptime( + things_task["start_date"], "%Y-%m-%d") + reclaim_task.due_date = datetime.strptime( + things_task["deadline"], "%Y-%m-%d") + + +def things_task_pretty_print(task, project_title): + print(f"\tTitle: {project_title} {task['title']}") + print(f"\tStart date: {task['start_date']}") + print(f"\tDeadline: {task['deadline']}") + + +def main(): + projects = extract_uni_projects() + reclaim_task_names = [task.name for task in ReclaimTask().search()] + for project in projects: + things_tasks = get_tasks_for_project(project) + for things_task in things_tasks: + full_task_name = "{} {}".format( + project["title"], things_task["title"]) + if full_task_name not in reclaim_task_names: + print(f"Creating task {full_task_name} in Reclaim") + things_task_pretty_print(things_task, project["title"]) + things_to_reclaim(things_task, project["title"]) + else: + print(f"Task {things_task['title']} already exists in Reclaim") + + +if __name__ == "__main__": + main()