From b0f4ca3843e539de5534c055e4cb1e52b1870572 Mon Sep 17 00:00:00 2001 From: Matt Snider Date: Thu, 8 Nov 2018 00:27:00 +0100 Subject: [PATCH] Refactor, improve output --- migrate.py | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/migrate.py b/migrate.py index 07f3ee2..3aaac58 100644 --- a/migrate.py +++ b/migrate.py @@ -26,19 +26,40 @@ def migrate(interactive): info(f'Todoist tasks: {len(todoist.items.all())}') for task in todoist.items.all(): - tid = task['id'] - name = task['content'] - info(f'Importing task #{tid}: {name}') - taskwarrior.task_add(name) + add_task(task) + + +def add_task(todoist_task): + """Add a taskwarrior task from todoist task + + Returns the taskwarrior task. + """ + tid = todoist_task['id'] + name = todoist_task['content'] + + info(f"Importing '{name}' (ID: {tid}) - ", nl=False) + try: + tw_task = taskwarrior.task_add(name) + except: + error('FAILED') + else: + success('OK') + return tw_task + """ Utils """ -def important(msg): - click.echo(click.style(msg, fg='blue', bold=True)) +def important(msg, **kwargs): + click.echo(click.style(msg, fg='blue', bold=True), **kwargs) +def info(msg, **kwargs): + click.echo(msg, **kwargs) -def info(msg): - click.echo(msg) +def success(msg, **kwargs): + click.echo(click.style(msg, fg='green', bold=True)) + +def error(msg, **kwargs): + click.echo(click.style(msg, fg='red', bold=True)) """ Entrypoint """