updated alembic
This commit is contained in:
@@ -20,6 +20,7 @@ import reclaim_handler
|
|||||||
from deadline_status import DeadlineStatus
|
from deadline_status import DeadlineStatus
|
||||||
import things_handler
|
import things_handler
|
||||||
import toggl_handler
|
import toggl_handler
|
||||||
|
import task_scheduler_handler
|
||||||
import utils
|
import utils
|
||||||
from database_handler import UploadedTasksDB
|
from database_handler import UploadedTasksDB
|
||||||
|
|
||||||
@@ -34,8 +35,7 @@ DATABASE_PATH = utils.get_project_root() / _config["database"]["path"]
|
|||||||
app = typer.Typer(add_completion=False, no_args_is_help=True)
|
app = typer.Typer(add_completion=False, no_args_is_help=True)
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
|
def generate_params_dict(things_task):
|
||||||
def things_to_reclaim(things_task):
|
|
||||||
tags = things_handler.get_task_tags(things_task)
|
tags = things_handler.get_task_tags(things_task)
|
||||||
estimated_time = tags.get("EstimatedTime")
|
estimated_time = tags.get("EstimatedTime")
|
||||||
if estimated_time is None:
|
if estimated_time is None:
|
||||||
@@ -62,9 +62,17 @@ def things_to_reclaim(things_task):
|
|||||||
)
|
)
|
||||||
|
|
||||||
utils.map_tag_values(things_task, tags, params)
|
utils.map_tag_values(things_task, tags, params)
|
||||||
|
return params
|
||||||
|
|
||||||
|
|
||||||
|
def things_to_reclaim(things_task):
|
||||||
|
params = generate_params_dict(things_task)
|
||||||
reclaim_handler.create_reaclaim_task_from_dict(params)
|
reclaim_handler.create_reaclaim_task_from_dict(params)
|
||||||
|
|
||||||
|
def things_to_task(things_task):
|
||||||
|
params = generate_params_dict(things_task)
|
||||||
|
task_scheduler_handler.create_task_from_dict(params)
|
||||||
|
|
||||||
|
|
||||||
def finish_task(task: Union[reclaim_handler.ReclaimTask, str]):
|
def finish_task(task: Union[reclaim_handler.ReclaimTask, str]):
|
||||||
"""
|
"""
|
||||||
@@ -452,6 +460,17 @@ def sync_things_and_reclaim(dry_run: bool = False):
|
|||||||
upload_things_to_reclaim(dry_run)
|
upload_things_to_reclaim(dry_run)
|
||||||
rprint("---------------------------------------------")
|
rprint("---------------------------------------------")
|
||||||
|
|
||||||
|
@app.command("upload_to_scheduler")
|
||||||
|
def upload_to_scheduler(dry_run: bool = False):
|
||||||
|
"""
|
||||||
|
Upload things tasks to task-scheduler
|
||||||
|
"""
|
||||||
|
tasks = things_handler.get_all_things_tasks()
|
||||||
|
for task in tasks:
|
||||||
|
print(f"Creating task {things_handler.full_name(task)} in Task Scheduler")
|
||||||
|
if not dry_run:
|
||||||
|
things_to_task(task)
|
||||||
|
print(f"Uploaded {len(tasks)} task{'s' if len(tasks) > 1 else ''}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app()
|
app()
|
||||||
|
|||||||
40
things2reclaim/task_scheduler_handler.py
Normal file
40
things2reclaim/task_scheduler_handler.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
from typing import Dict, List
|
||||||
|
|
||||||
|
from task_scheduler_client.configuration import Configuration
|
||||||
|
from task_scheduler_client.api.default_api import DefaultApi
|
||||||
|
from task_scheduler_client.api_client import ApiClient
|
||||||
|
from task_scheduler_client.models.task import Task
|
||||||
|
|
||||||
|
client = ApiClient(Configuration(host="http://localhost:8000"))
|
||||||
|
api = DefaultApi(client)
|
||||||
|
|
||||||
|
def get_tasks() -> List[Task]:
|
||||||
|
return api.get_tasks_tasks_get()
|
||||||
|
|
||||||
|
def remap_dict_keys(params: Dict):
|
||||||
|
key_mapping = {"min_work_duration": "min_time", "max_work_duration": "max_work", "duration": "estimated_time", "due_date": "deadline", "description": "things_id"}
|
||||||
|
return {key_mapping.get(k,k): v for k, v in params.items()}
|
||||||
|
|
||||||
|
def remove_keys(params: Dict):
|
||||||
|
keys_to_remove = {"tags"}
|
||||||
|
return {k: v for k, v in params.items() if k not in keys_to_remove}
|
||||||
|
|
||||||
|
def change_value(params: Dict):
|
||||||
|
keys_to_change = {"things_id": "things_task:"}
|
||||||
|
return {k: (v if k not in keys_to_change else v.removeprefix(keys_to_change[k])) for k, v in params.items()}
|
||||||
|
|
||||||
|
def param_dict_to_task(params: Dict):
|
||||||
|
remapped_keys = remap_dict_keys(params)
|
||||||
|
stripped_keys = remove_keys(remapped_keys)
|
||||||
|
return change_value(stripped_keys)
|
||||||
|
|
||||||
|
def create_task(task: Task):
|
||||||
|
api.create_task_tasks_post(task)
|
||||||
|
|
||||||
|
def create_task_from_dict(params: Dict):
|
||||||
|
params = param_dict_to_task(params)
|
||||||
|
task = Task.from_dict(params)
|
||||||
|
if task is None:
|
||||||
|
raise ValueError
|
||||||
|
api.create_task_tasks_post(task)
|
||||||
|
|
||||||
Reference in New Issue
Block a user