From a8fd28afaeee59e53e11e9f9faf24568487500fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Bu=C3=9Fmann?= Date: Tue, 18 Jun 2024 03:06:08 +0200 Subject: [PATCH] updated formatting --- things2reclaim/main.py | 23 ++++++++++++++--------- things2reclaim/reclaim_handler.py | 3 +++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/things2reclaim/main.py b/things2reclaim/main.py index fc60db9..784a87b 100755 --- a/things2reclaim/main.py +++ b/things2reclaim/main.py @@ -23,7 +23,6 @@ from typing_extensions import Annotated import typer - CONFIG_PATH = Path("config/.things2reclaim.toml") _config = {} @@ -33,7 +32,7 @@ with open(CONFIG_PATH, "rb") as f: DATABASE_PATH = _config["database"]["path"] app = typer.Typer( - add_completion=False, no_args_is_help=True, pretty_exceptions_enable=False + add_completion=False, no_args_is_help=True ) console = Console() @@ -129,7 +128,8 @@ def upload_things_to_reclaim(verbose: bool = False): else: if verbose: print( - f"Task {things_task['title']} already exists in Reclaim") + f"Task {things_task['title']} \ + already exists in Reclaim") if tasks_uploaded == 0: rprint("No new tasks were found") elif tasks_uploaded == 1: @@ -138,7 +138,8 @@ def upload_things_to_reclaim(verbose: bool = False): @app.command("list") -def list_reclaim_tasks(subject: Annotated[Optional[str], typer.Argument()] = None): +def list_reclaim_tasks(subject: Annotated[Optional[str], + typer.Argument()] = None): """ List all current tasks """ @@ -168,7 +169,7 @@ def list_reclaim_tasks(subject: Annotated[Optional[str], typer.Argument()] = Non @app.command("start") def start_task( - task_name_parts: Annotated[List[str], typer.Argument(help="Task to start")], + task_name_parts: Annotated[List[str], typer.Argument(help="Task to start")] ): task_name = (" ").join(task_name_parts) tasks: Dict[str, reclaim_handler.ReclaimTask] = { @@ -234,8 +235,10 @@ def stop_task(): time_format = "%H:%M" local_zone = tz.gettz() rprint( - f"""Logged work from {current_task.start.astimezone(local_zone).strftime(time_format)} - to {stop_time.astimezone(local_zone).strftime(time_format)} for {stopped_task.name}""" + f"Logged work from \ + {current_task.start.astimezone(local_zone).strftime(time_format)} to \ + {stop_time.astimezone(local_zone).strftime(time_format)} \ + for {stopped_task.name}" ) @@ -256,10 +259,12 @@ def show_task_stats(): course_names = things_handler.get_course_names() for course_name in course_names: fine_per_course.append( - str(len(reclaim_handler.filter_for_subject(course_name, tasks_fine))) + str(len(reclaim_handler.filter_for_subject + (course_name, tasks_fine))) ) overdue_per_course.append( - str(len(reclaim_handler.filter_for_subject(course_name, tasks_overdue))) + str(len(reclaim_handler.filter_for_subject + (course_name, tasks_overdue))) ) table = Table(*(["Status"] + course_names)) diff --git a/things2reclaim/reclaim_handler.py b/things2reclaim/reclaim_handler.py index 0bf3149..042dea3 100644 --- a/things2reclaim/reclaim_handler.py +++ b/things2reclaim/reclaim_handler.py @@ -63,6 +63,9 @@ def log_work_for_task(task: ReclaimTask, start: datetime, end: datetime): if not task.is_scheduled: raise RuntimeError("Task is not scheduled") + if not task.events: + raise RuntimeError("Event list is empty") + last_event: ReclaimTaskEvent = task.events[-1] last_event.start = start.astimezone(utc)