Skip to content

Commit

Permalink
Fix GCCollector updating game version info, a little cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SyberiaK committed Apr 17, 2024
1 parent 0a7969e commit 9b5336b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
22 changes: 10 additions & 12 deletions collectors/game_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
7 changes: 0 additions & 7 deletions utypes/profiles.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from dataclasses import astuple, dataclass
from enum import StrEnum
import hashlib
import logging
import re
from typing import NamedTuple, Self

Expand All @@ -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)


Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 9b5336b

Please sign in to comment.