home · contact · privacy
Store relevant lines in Booking, calc ending index from their number.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 20 Jan 2025 11:05:17 +0000 (12:05 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 20 Jan 2025 11:05:17 +0000 (12:05 +0100)
ledger.py

index eee9c5d4e960d1d98c69dac5d9e5538ee34a5c69..2a1fdd6a196dcfa11624dfe208e8cd5674f9f11b 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -60,9 +60,11 @@ class Booking:
     """Represents lines of individual booking."""
     # pylint: disable=too-few-public-methods
 
-    def __init__(self, id_: int, idx_start_end: tuple[int, int]) -> None:
+    def __init__(self, id_: int, idx_start: int, b_lines: list[str]) -> None:
         self.id_ = id_
-        self.idx_start, self.idx_end = idx_start_end
+        self.idx_start = idx_start
+        self.b_lines = b_lines
+        self.idx_end = self.idx_start + len(self.b_lines)
 
 
 class Handler(PlomHttpHandler):
@@ -97,17 +99,18 @@ class Server(PlomHttpServer):
                 for line in path_dat.read_text(encoding='utf8').splitlines()]
         self.bookings: list[Booking] = []
         code_lines = [dl.code for dl in self.dat_lines]
-        in_booking = False
         last_booking_start = -1
+        b_lines: list[str] = []
         for idx, code in enumerate(code_lines + ['']):
-            if in_booking and not code:
-                in_booking = False
+            if code:
+                if not b_lines:
+                    last_booking_start = idx
+                b_lines += [code]
+            elif b_lines:
                 self.bookings += [Booking(len(self.bookings),
-                                          (last_booking_start, idx))]
+                                          last_booking_start, b_lines)]
+                b_lines.clear()
                 self.dat_lines[last_booking_start].booking = self.bookings[-1]
-            elif code and not in_booking:
-                in_booking = True
-                last_booking_start = idx
 
     @property
     def dat_lines_sans_empty(self) -> list[DatLine]: