From 6f272ff021190ed6478da52d62343b0b7a1a84f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Bu=C3=9Fmann?= Date: Sat, 15 Jun 2024 18:42:52 +0200 Subject: [PATCH] made pylint happy and added enviorment files --- .DS_Store | Bin 6148 -> 6148 bytes .gitignore | 1 + .pylintrc | 6 +++ README.md | 2 + api/ReclaimAI/Get Events.bru | 18 +++++++ api/ReclaimAI/Get Tasks.bru | 11 +++++ api/ReclaimAI/bruno.json | 13 +++++ environment.yml | 41 +++++++++++++++ requirements.txt | 77 +++++++++++++++++++++++++++++ things2reclaim/database_handler.py | 4 +- things2reclaim/main.py | 39 ++++++++------- things2reclaim/reclaim_handler.py | 6 ++- things2reclaim/things_handler.py | 4 +- things2reclaim/toggl_handler.py | 27 +++++----- things2reclaim/utils.py | 13 ++--- 15 files changed, 218 insertions(+), 44 deletions(-) create mode 100644 .pylintrc create mode 100644 api/ReclaimAI/Get Events.bru create mode 100644 api/ReclaimAI/Get Tasks.bru create mode 100644 api/ReclaimAI/bruno.json create mode 100644 environment.yml create mode 100644 requirements.txt diff --git a/.DS_Store b/.DS_Store index 001c6ec7b1e06f2710bdce2c155ec61a90abc636..f299ed6958d11b4fafe396e6db7e89ba5025418b 100644 GIT binary patch delta 143 zcmZoMXfc@J&nUDpU^g?P&}JSMZN^+?hD3$}hRmFF!{Frn+yVv!fXd|NySOCf task.due_date: days_behind = (current_date - task.due_date).days table.add_row( - f"({id + 1})", + f"({index + 1})", task.name, Text(f"{days_behind} days overdue", style="bold red"), ) else: days_left = (task.due_date - current_date).days table.add_row( - f"({id + 1})", + f"({index + 1})", task.name, Text(f"{days_left} days left", style="bold white"), ) @@ -223,7 +224,8 @@ 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}""" ) @@ -278,7 +280,8 @@ def print_time_needed(): today = datetime.now(tz.tzutc()) print( - f"Last task is scheduled for {last_task_date.strftime('%d.%m.%Y')} ({last_task_date - today} till completion)" + f"""Last task is scheduled for {last_task_date.strftime('%d.%m.%Y')} + ({last_task_date - today} till completion)""" ) diff --git a/things2reclaim/reclaim_handler.py b/things2reclaim/reclaim_handler.py index 83bf985..a730ce6 100644 --- a/things2reclaim/reclaim_handler.py +++ b/things2reclaim/reclaim_handler.py @@ -32,6 +32,10 @@ def get_project(task: ReclaimTask): return task.name.split(" ")[0] +def get_events(since_days: int = 1): + return ReclaimTaskEvent.search() + + def start_task(task: ReclaimTask): task.prioritize() @@ -61,7 +65,7 @@ def log_work_for_task(task: ReclaimTask, start: datetime, end: datetime): last_event.start = start.astimezone(utc) last_event.end = end.astimezone(utc) - last_event._update() + last_event.save() def finish_task(task: ReclaimTask): diff --git a/things2reclaim/things_handler.py b/things2reclaim/things_handler.py index de0a6c3..c9c62e1 100644 --- a/things2reclaim/things_handler.py +++ b/things2reclaim/things_handler.py @@ -4,7 +4,7 @@ import tomllib import things -from database_handler import UploadedTasksDB +from things2reclaim.database_handler import UploadedTasksDB _config = {} CONFIG_PATH = Path("config/.things2reclaim.toml") @@ -49,7 +49,7 @@ def get_all_uploaded_things_tasks() -> List: def get_task_tags(things_task: Dict) -> Dict[str, str]: - return {k: v for (k, v) in [tag.split(": ") for tag in things_task["tags"]]} + return dict([tag.split(": ") for tag in things_task["tags"]]) def full_name(things_task) -> str: diff --git a/things2reclaim/toggl_handler.py b/things2reclaim/toggl_handler.py index 82e07ec..020bc62 100644 --- a/things2reclaim/toggl_handler.py +++ b/things2reclaim/toggl_handler.py @@ -1,13 +1,12 @@ -from toggl_python.entities import TimeEntry -import toggl_python -import tomllib -from pathlib import Path -from dateutil import tz import difflib - from datetime import datetime, timedelta -from better_rich_prompts.prompt import ListPrompt +from pathlib import Path +import tomllib +import toggl_python +from better_rich_prompts.prompt import ListPrompt +from dateutil import tz +from toggl_python.entities import TimeEntry _config = {} @@ -29,8 +28,8 @@ time_entry_editor = toggl_python.WorkspaceTimeEntries( ) -def get_time_entry(id: int): - return toggl_python.TimeEntries(auth=auth).retrieve(id) +def get_time_entry(time_entry_id: int): + return toggl_python.TimeEntries(auth=auth).retrieve(time_entry_id) def get_time_entries(since_days: int = 30): @@ -65,14 +64,13 @@ def get_approriate_tag(description: str) -> str | None: if not possible_tags: print("Found no matching tags") - return + return None possible_tags = list(possible_tags) if len(possible_tags) == 1: return possible_tags[0] - else: - return ListPrompt.ask("Select the best fitting tag", possible_tags) + return ListPrompt.ask("Select the best fitting tag", possible_tags) def create_task_time_entry( @@ -95,9 +93,8 @@ def create_task_time_entry( if start is not None: if start.tzinfo is None: raise ValueError("start has to be timezone aware") - else: - start = start.astimezone(tz.tzutc()) - time_entry.start = start + start = start.astimezone(tz.tzutc()) + time_entry.start = start tag = get_approriate_tag(description) if tag: diff --git a/things2reclaim/utils.py b/things2reclaim/utils.py index df15058..2e6b3ce 100644 --- a/things2reclaim/utils.py +++ b/things2reclaim/utils.py @@ -3,14 +3,15 @@ import re from typing import Union, Dict, Any, List import difflib -from rich import print as rprint -import things_handler from better_rich_prompts.prompt import ListPrompt +from rich import print as rprint -regex = ( +from things2reclaim import things_handler + +TIME_PATTERN = ( r"((\d+\.?\d*) (hours|hrs|hour|hr|h))? ?((\d+\.?\d*) (mins|min|minutes|minute|m))?" ) -pattern = re.compile(regex) +pattern = re.compile(TIME_PATTERN) def calculate_time_on_unit(tag_value: str) -> float: @@ -65,8 +66,8 @@ def get_closest_match(name: str, candidates: Dict[str, Any]) -> Any | None: return None if len(possible_candidates) == 1: return candidates[possible_candidates[0]] - else: - return candidates[ListPrompt.ask("Select a candidate", possible_candidates)] + + return candidates[ListPrompt.ask("Select a candidate", possible_candidates)] def pinfo(msg: str):