From 9b5336be668ed2a57a978f693192f1cfbc812d44 Mon Sep 17 00:00:00 2001 From: SyberiaK Date: Wed, 17 Apr 2024 18:58:18 +0500 Subject: [PATCH] Fix GCCollector updating game version info, a little cleanup --- collectors/game_coordinator.py | 22 ++++++++++------------ utypes/profiles.py | 7 ------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/collectors/game_coordinator.py b/collectors/game_coordinator.py index 4d88e3f..cc21327 100644 --- a/collectors/game_coordinator.py +++ b/collectors/game_coordinator.py @@ -107,7 +107,7 @@ async def update_depots(self): return if public_build_id != self.cache.get('public_build_id'): - t = asyncio.create_task(self.update_game_version()) + _ = asyncio.create_task(self.update_game_version()) self.update_cache({ 'public_build_id': public_build_id, @@ -126,25 +126,23 @@ async def update_game_version(self): try: data = GameVersion.request() - # Made to ensure we will grab the latest public data if we *somehow* don't have anything cached - no_cached_data = (self.cache.get('cs2_client_version') is None) + no_version_data_cached = (data.cs2_client_version is None) + version_has_changed = (data.cs2_client_version != self.cache.get('cs2_client_version')) - # We also want to ensure that the data is up to date, so we check datetime - new_data_datetime = (dt.datetime.fromisoformat(data.cs2_version_timestamp) - .replace(tzinfo=VALVE_TIMEZONE).astimezone(dt.UTC)) - logging.info(f'{new_data_datetime=}') - is_up_to_date = utime.utcnow() - new_data_datetime < dt.timedelta(hours=12) - logging.info(f'{utime.utcnow()=}') - logging.info(f'{is_up_to_date=}') + # We also want the data to be up-to-date, so we check datetime + new_version_datetime = (dt.datetime.fromtimestamp(data.cs2_version_timestamp) + .replace(tzinfo=VALVE_TIMEZONE).astimezone(dt.UTC)) - if no_cached_data or (is_up_to_date and data.cs2_client_version != self.cache.get('cs2_client_version')): + is_up_to_date = utime.utcnow() - new_version_datetime < dt.timedelta(hours=12) + + if no_version_data_cached or (version_has_changed and is_up_to_date): self.update_cache(data.asdict()) return except Exception: logging.exception('Caught an exception while trying to get new version!') await asyncio.sleep(45) - # sometimes steamdb updates the info much later (xPaw: Zzz...) + # sometimes SteamDB updates the info much later (xPaw: Zzz...) # because of this, we retry in an hour await asyncio.sleep(60 * 60) await self.update_game_version() diff --git a/utypes/profiles.py b/utypes/profiles.py index 4850c81..b59d952 100644 --- a/utypes/profiles.py +++ b/utypes/profiles.py @@ -1,7 +1,6 @@ from dataclasses import astuple, dataclass from enum import StrEnum import hashlib -import logging import re from typing import NamedTuple, Self @@ -17,11 +16,6 @@ STEAM_PROFILE_LINK_PATTERN = re.compile(r'(?:https?://)?steamcommunity\.com/(?:profiles|id)/[a-zA-Z0-9]+(/?)\w') _csgofrcode_chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789" - -logging.basicConfig(level=logging.INFO, - format="%(asctime)s | %(name)s: %(message)s", - datefmt="%H:%M:%S — %d/%m/%Y") - api = SteamWebAPI(config.STEAM_API_KEY) @@ -254,7 +248,6 @@ async def get(cls, data) -> Self: if not response: raise ParseUserStatsError(ErrorCode.PROFILE_IS_PRIVATE) - logging.info(response) if response.get('playerstats') is None or response['playerstats'].get('stats') is None: raise ParseUserStatsError(ErrorCode.NO_STATS_AVAILABLE)