feat: set up modularized version of project with testing
This commit is contained in:
commit
7bea08ddac
19 changed files with 1138 additions and 0 deletions
29
src/timesheets/projects.py
Normal file
29
src/timesheets/projects.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import json
|
||||
import sys
|
||||
|
||||
|
||||
def load_project_map(path: str | None) -> dict:
|
||||
"""Load a project map JSON file. Returns an empty dict if path is None or missing."""
|
||||
if not path:
|
||||
return {}
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except FileNotFoundError:
|
||||
print(f"Warning: project map file not found: {path}", file=sys.stderr)
|
||||
return {}
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"Warning: could not parse project map file: {e}", file=sys.stderr)
|
||||
return {}
|
||||
|
||||
|
||||
def resolve_project_task(raw_project: str, project_map: dict) -> tuple[str, str]:
|
||||
"""
|
||||
Look up a raw project key in the project map.
|
||||
Returns (Project, Task) if found, or (raw_project, "") as fallback.
|
||||
"""
|
||||
key = raw_project.strip().lower()
|
||||
entry = project_map.get(key) or project_map.get(raw_project.strip())
|
||||
if entry:
|
||||
return entry.get("Project", raw_project), entry.get("Task", "")
|
||||
return raw_project, ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue