From 156056e9c31468564fb53ca284996a5de41471fb Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Wed, 16 Oct 2024 23:28:46 +0200 Subject: Working version with all functionality --- model.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'model.py') diff --git a/model.py b/model.py index f768d0f..c69ba48 100644 --- a/model.py +++ b/model.py @@ -1,6 +1,7 @@ from math import floor from csv import reader from typing import Tuple +from time import time, strftime from dataclasses import dataclass MIN_LEVEL = 1 @@ -101,3 +102,35 @@ class PlayerList: } players.update(guests) return players + + +@dataclass +class Timer: + ref: float = None + running: bool = False + max_mins: int = 1 + default: str = ("00", "00") + + def __post_init__(self): + self.max_seconds = self.max_mins * 60 + + def start(self): + self.ref = time() + self.max_seconds + self.running = True + + def stop(self): + self.ref = None + self.running = False + + def get(self): + if not self.running: + return self.default + total_seconds = self.ref - time() + if total_seconds < 0: + self.stop() + return self.default + mins = f"{int(total_seconds // 60):02d}" + secs = f"{int(total_seconds % 60):02d}" + print(mins) + print(secs) + return mins, secs -- cgit v1.3.1