Better import and get next run time

This commit is contained in:
Pascal P. 2026-08-04 08:49:46 +02:00
parent 5e5a56009c
commit b396602dee
1 changed files with 11 additions and 11 deletions

View File

@ -1,7 +1,7 @@
import httpx import httpx
from supabase import create_client, Client from supabase import create_client, Client
from loguru import logger from loguru import logger
import datetime from datetime import datetime, timedelta, timezone
from ..lib.supabase_cookie import get_auth_cookies from ..lib.supabase_cookie import get_auth_cookies
from ..lib.utils import HumanReadable as hr from ..lib.utils import HumanReadable as hr
# supabase ? # supabase ?
@ -18,6 +18,8 @@ class WikiMastersClient:
SUPABASE_URL = "https://cyrxjeppjqsxxjayfrur.supabase.co" SUPABASE_URL = "https://cyrxjeppjqsxxjayfrur.supabase.co"
SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImN5cnhqZXBwanFzeHhqYXlmcnVyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzM4ODAzMzksImV4cCI6MjA4OTQ1NjMzOX0.BZluyXygNxuQGDPxFX1zG5i-cqp10CVK-8GGtuak4Rg" SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImN5cnhqZXBwanFzeHhqYXlmcnVyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzM4ODAzMzksImV4cCI6MjA4OTQ1NjMzOX0.BZluyXygNxuQGDPxFX1zG5i-cqp10CVK-8GGtuak4Rg"
ONE_PACK_TIME = timedelta(minutes=10)
def __init__(self) -> None: def __init__(self) -> None:
self.logger = logger.bind(service=self.__class__.__name__) self.logger = logger.bind(service=self.__class__.__name__)
@ -74,20 +76,18 @@ class WikiMastersClient:
_id = d["id"] _id = d["id"]
_username = d["username"] _username = d["username"]
_packs_remaining = d["packs_remaining"] _packs_remaining = d["packs_remaining"]
_packs_last_regen_at = datetime.datetime.fromisoformat( _packs_last_regen_at = datetime.fromisoformat(
d["packs_last_regen_at"] d["packs_last_regen_at"]
) )
# Does this math still works when we are opening the 9th pack ? # Does this math still works when we are opening the 9th pack ?
next_pack_in = WikiMastersClient.ONE_PACK_TIME - (
datetime.now(tz=timezone.utc) - _packs_last_regen_at
)
next_run_in = next_pack_in + WikiMastersClient.ONE_PACK_TIME * (9 - _packs_remaining) - timedelta(seconds=10)
self.logger.info( self.logger.info(
"Next pack is in {}", "Next pack is in {}",
hr.seconds_to_human( hr.seconds_to_human(next_pack_in.total_seconds()),
(
datetime.timedelta(minutes=10)
- (
datetime.datetime.now(tz=datetime.timezone.utc)
- _packs_last_regen_at
)
).total_seconds()
),
) )
self.logger.debug("We should schedule in {}", hr.seconds_to_human(next_run_in.total_seconds()))