From 5e5a56009cfdf794298a6394b658b1b6a5736255 Mon Sep 17 00:00:00 2001 From: "Pascal P." Date: Tue, 4 Aug 2026 08:43:25 +0200 Subject: [PATCH] Added estimation for next pack time (need to check what happened on 10 opening) --- src/lib/utils.py | 16 ++++++++++++++++ src/services/wiki_masters.py | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/lib/utils.py b/src/lib/utils.py index 1727957..2acac57 100644 --- a/src/lib/utils.py +++ b/src/lib/utils.py @@ -12,3 +12,19 @@ class EveryRunRotator: self.rotate = False return True return False + +class HumanReadable: + @staticmethod + def seconds_to_human(seconds: int|float): + output = "" + h = seconds // 3600 + m = (seconds - h * 3600) // 60 + s = seconds - (h * 3600) - (m * 60) + + if h > 0: + output += f"{int(h)} hours " + if m > 0 or h > 0: + output += f"{int(m)} min " + output += f"{int(s):02}s" + + return output \ No newline at end of file diff --git a/src/services/wiki_masters.py b/src/services/wiki_masters.py index 53526b4..7e87af6 100644 --- a/src/services/wiki_masters.py +++ b/src/services/wiki_masters.py @@ -1,7 +1,9 @@ import httpx from supabase import create_client, Client from loguru import logger +import datetime from ..lib.supabase_cookie import get_auth_cookies +from ..lib.utils import HumanReadable as hr # supabase ? # https://cyrxjeppjqsxxjayfrur.supabase.co/auth/v1/token?grant_type=password # https://cyrxjeppjqsxxjayfrur.supabase.co/auth/v1/user @@ -67,3 +69,25 @@ class WikiMastersClient: "sync_profile_packs", {"user_id": session.user.id} ).execute() self.logger.info("info sync: {}", response) + + d = response.data[0] + _id = d["id"] + _username = d["username"] + _packs_remaining = d["packs_remaining"] + _packs_last_regen_at = datetime.datetime.fromisoformat( + d["packs_last_regen_at"] + ) + + # Does this math still works when we are opening the 9th pack ? + self.logger.info( + "Next pack is in {}", + hr.seconds_to_human( + ( + datetime.timedelta(minutes=10) + - ( + datetime.datetime.now(tz=datetime.timezone.utc) + - _packs_last_regen_at + ) + ).total_seconds() + ), + )