Skip to content

Commit

Permalink
feat: prettify hours
Browse files Browse the repository at this point in the history
  • Loading branch information
pesaventofilippo committed Nov 22, 2024
1 parent 5318b4d commit a60239b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
22 changes: 15 additions & 7 deletions modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,16 +37,12 @@ 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() \
.replace("{ore}", ore) \
.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
2 changes: 1 addition & 1 deletion pages/entrata_lab.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</head>
<body>
<h1>Attualmente NON sei in lab 😕</h1>
<h3>Totale oggi: {ore_oggi} ore</h3>
<h3>Totale oggi: {ore_oggi}</h3>
<form method="POST" onsubmit="formSubmit(event)">
<button type="submit">Entra in Lab</button>
</form>
Expand Down
4 changes: 2 additions & 2 deletions pages/uscita_lab.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
</style>
</head>
<body>
<h1>Attualmente sei in lab da: {ore} ore</h1>
<h3>Totale oggi: {ore_oggi} ore {happy_hour_emoji}</h3>
<h1>Attualmente sei in lab da: {ore}</h1>
<h3>Totale oggi: {ore_oggi} {happy_hour_emoji}</h3>
<form method="POST" onsubmit="formSubmit(event)">
<button type="submit">Esci dal Lab</button>
</form>
Expand Down

0 comments on commit a60239b

Please sign in to comment.