Better import and get next run time
This commit is contained in:
parent
5e5a56009c
commit
b396602dee
|
|
@ -1,7 +1,7 @@
|
|||
import httpx
|
||||
from supabase import create_client, Client
|
||||
from loguru import logger
|
||||
import datetime
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from ..lib.supabase_cookie import get_auth_cookies
|
||||
from ..lib.utils import HumanReadable as hr
|
||||
# supabase ?
|
||||
|
|
@ -18,6 +18,8 @@ class WikiMastersClient:
|
|||
SUPABASE_URL = "https://cyrxjeppjqsxxjayfrur.supabase.co"
|
||||
SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImN5cnhqZXBwanFzeHhqYXlmcnVyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzM4ODAzMzksImV4cCI6MjA4OTQ1NjMzOX0.BZluyXygNxuQGDPxFX1zG5i-cqp10CVK-8GGtuak4Rg"
|
||||
|
||||
ONE_PACK_TIME = timedelta(minutes=10)
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.logger = logger.bind(service=self.__class__.__name__)
|
||||
|
||||
|
|
@ -74,20 +76,18 @@ class WikiMastersClient:
|
|||
_id = d["id"]
|
||||
_username = d["username"]
|
||||
_packs_remaining = d["packs_remaining"]
|
||||
_packs_last_regen_at = datetime.datetime.fromisoformat(
|
||||
_packs_last_regen_at = datetime.fromisoformat(
|
||||
d["packs_last_regen_at"]
|
||||
)
|
||||
|
||||
# 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(
|
||||
"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()
|
||||
),
|
||||
hr.seconds_to_human(next_pack_in.total_seconds()),
|
||||
)
|
||||
self.logger.debug("We should schedule in {}", hr.seconds_to_human(next_run_in.total_seconds()))
|
||||
|
|
|
|||
Loading…
Reference in New Issue