]> git.walde.dev - punch/commitdiff
Begin refactor
authorDustin Walde <redacted>
Tue, 25 Apr 2023 17:15:30 +0000 (10:15 -0700)
committerDustin Walde <redacted>
Tue, 25 Apr 2023 17:15:30 +0000 (10:15 -0700)
- Prepping for image generation, tray icon goals
- Move to multi file library instead of monoscript

src/category.py [new file with mode: 0644]
src/entry.py [new file with mode: 0644]

diff --git a/src/category.py b/src/category.py
new file mode 100644 (file)
index 0000000..0f7f905
--- /dev/null
@@ -0,0 +1,35 @@
+# ©2023 Dustin Walde — GPL-3.0-or-later
+
+from typing import Optional, List
+
+
+class Category:
+
+    def __init__(self, abbr: str, name: str,
+                 color: str = '#888',
+                 parent: Optional[str] = None,
+                 children: Optional[List[str]] = None) -> None:
+        self.abbr = abbr
+        self.name = name
+        self.color = color
+        self.parent = parent
+        self.children = children
+
+
+    @property
+    def is_group(self) -> bool:
+        return self.children is not None
+
+
+    def as_rows(self) -> List[List[str]]:
+        parent = self.parent
+        if parent is None:
+            parent = ""
+        if self.children is None:
+            color = self.color
+            if color is None:
+                color = ""
+            return [[self.abbr, "category", self.name, parent, color]]
+        else:
+            return [["", "group", self.abbr, self.name, parent]]
+
diff --git a/src/entry.py b/src/entry.py
new file mode 100644 (file)
index 0000000..93a3a06
--- /dev/null
@@ -0,0 +1,30 @@
+# ©2023 Dustin Walde — GPL-3.0-or-later
+
+from datetime import datetime, timedelta
+from typing import List, Optional
+
+
+class Entry:
+
+    def __init__(self, category: str, t_in: datetime, t_out: Optional[datetime]) -> None:
+        self.category = category
+        self.t_in = t_in
+        self.t_out = t_out
+
+
+    def as_rows(self) -> List[List[str]]:
+        rows = []
+        rows.append([self.category, "in", self.t_in.isoformat()])
+        if self.t_out is not None:
+            rows.append([self.category, "out", self.t_out.isoformat()])
+        return rows
+
+
+    def duration(self, use_now: bool = False) -> timedelta:
+        out = self.t_out
+        if out is None and use_now:
+            out = datetime.now()
+        if out is None:
+            return timedelta(0)
+        return out - self.t_in
+