From a60239b063bf6080bc01979f53557a1209e219b2 Mon Sep 17 00:00:00 2001 From: Filippo Pesavento Date: Fri, 22 Nov 2024 12:15:36 +0100 Subject: [PATCH] feat: prettify hours --- modules/utils.py | 22 +++++++++++++++------- pages/entrata_lab.html | 2 +- pages/uscita_lab.html | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/modules/utils.py b/modules/utils.py index 393e194..c98296a 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -7,8 +7,20 @@ def get_eagletrt_email(email: str) -> str: return f"{username}@eagletrt.it" +def timedelta_to_hours(td: timedelta) -> float: + return td.total_seconds() / 3600 + + +def pretty_time(hours: float) -> str: + int_hours = int(hours) + minutes = int((hours - int_hours) * 60) + if hours < 1: + return f"{minutes} minuti" + return f"{int_hours}h {minutes}min" + + def orelab_entrata(ore_oggi: float) -> HTMLResponse: - ore_oggi = str(round(ore_oggi, 2)) + ore_oggi = pretty_time(ore_oggi) with open("pages/entrata_lab.html") as f: res = f.read() \ .replace("{ore_oggi}", ore_oggi) @@ -25,8 +37,8 @@ def orelab_uscita(ore: float, ore_oggi: float) -> HTMLResponse: 5: "😎" } emoji = emoji_dict.get(int(ore_oggi // 1), "🥹") - ore = str(round(ore, 2)) - ore_oggi = str(round(ore_oggi, 2)) + ore = pretty_time(ore) + ore_oggi = pretty_time(ore_oggi) with open("pages/uscita_lab.html") as f: res = f.read() \ @@ -34,7 +46,3 @@ def orelab_uscita(ore: float, ore_oggi: float) -> HTMLResponse: .replace("{ore_oggi}", ore_oggi) \ .replace("{happy_hour_emoji}", emoji) return HTMLResponse(content=res, status_code=200) - - -def timedelta_to_hours(td: timedelta) -> float: - return td.total_seconds() / 3600 diff --git a/pages/entrata_lab.html b/pages/entrata_lab.html index e63a299..15a5ca5 100644 --- a/pages/entrata_lab.html +++ b/pages/entrata_lab.html @@ -41,7 +41,7 @@

Attualmente NON sei in lab 😕

-

Totale oggi: {ore_oggi} ore

+

Totale oggi: {ore_oggi}

diff --git a/pages/uscita_lab.html b/pages/uscita_lab.html index 206ad17..ca9dd7d 100644 --- a/pages/uscita_lab.html +++ b/pages/uscita_lab.html @@ -46,8 +46,8 @@ -

Attualmente sei in lab da: {ore} ore

-

Totale oggi: {ore_oggi} ore {happy_hour_emoji}

+

Attualmente sei in lab da: {ore}

+

Totale oggi: {ore_oggi} {happy_hour_emoji}