From 32b0fa3392e8cf5e3ad993ac3c3b691b674b3968 Mon Sep 17 00:00:00 2001 From: Nahuel Lofeudo Date: Sun, 23 Apr 2023 06:32:26 +0100 Subject: [PATCH] If the arrival is due in > 99min, show the arrival time instead --- arrival_times.py | 9 +++++++++ main.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arrival_times.py b/arrival_times.py index 59ab922..0d7e041 100644 --- a/arrival_times.py +++ b/arrival_times.py @@ -1,3 +1,5 @@ +import datetime + class ArrivalTime(): """ Represents the arrival times of buses at one of the configured stops """ @@ -14,5 +16,12 @@ class ArrivalTime(): def isDue(self) -> bool: return self.due_in_minutes < 1 + def due_in_str(self) -> str: + if self.due_in_minutes < 99: + return str(self.due_in_minutes) + "min" + else: + due_in = datetime.datetime.now() + datetime.timedelta(0, self.due_in_seconds) + return due_in.strftime("%H:%M") + def __lt__(self, other) -> int: return self.due_in_seconds < other.due_in_seconds \ No newline at end of file diff --git a/main.py b/main.py index b46123d..eeb65a7 100755 --- a/main.py +++ b/main.py @@ -96,7 +96,7 @@ def update_screen(updates: list[ArrivalTime]) -> None: line=line_num, route=update.route_id, destination=update.destination, - time_left='Due' if update.isDue() else f'{update.due_in_minutes}min', + time_left='Due' if update.isDue() else update.due_in_str(), time_color=lcd_color )