diff --git a/personal_data/fetchers/psnprofiles.py b/personal_data/fetchers/psnprofiles.py index dbb4f41..bde2d76 100644 --- a/personal_data/fetchers/psnprofiles.py +++ b/personal_data/fetchers/psnprofiles.py @@ -21,6 +21,8 @@ URL_USER_GAME_TROPHIES = URL_API_ROOT + 'trophies/{game_id}/{psn_id}' URL_GAMES_OVERVIEW = URL_API_ROOT + '{psn_id}' +PSN_PROFILES_DEFAULT_TIMEZONE=datetime.UTC + def game_psnprofiles_id_from_url(relative_url: str) -> int: m = re.match(r'/(?:trophy|trophies)/(\d+)\-(?:[\w-]+)(/[\w-]*)?', relative_url) result = m.group(1) @@ -195,7 +197,7 @@ class PsnProfiles(Scraper): if 'Missing\nTimestamp' in cells[2].get_text().strip(): continue cells[2].span.span.nobr.sup.extract() - gotten_at = parse_util.parse_time(cells[2].get_text()) + gotten_at = parse_util.parse_time(cells[2].get_text(), timezone=PSN_PROFILES_DEFAULT_TIMEZONE) yield { 'game.name': game_name, diff --git a/personal_data/parse_util.py b/personal_data/parse_util.py index ec8b468..846f4f9 100644 --- a/personal_data/parse_util.py +++ b/personal_data/parse_util.py @@ -41,14 +41,12 @@ LOCAL_TIMEZONE = NOW.astimezone().tzinfo def try_parse(text: str, fmt: str) -> datetime.datetime | None: try: time = datetime.datetime.strptime(text, fmt) # noqa: DTZ007 - if time.tzinfo is None: - time = time.replace(tzinfo=LOCAL_TIMEZONE) except ValueError: time = None return time -def parse_time(text: str) -> datetime.datetime: +def parse_time(text: str, timezone = LOCAL_TIMEZONE) -> datetime.datetime: text = text.replace('\n', ' ') text = text.strip() @@ -62,7 +60,7 @@ def parse_time(text: str) -> datetime.datetime: raise RuntimeError(msg) if time.tzinfo is None: - time = time.replace(tzinfo=LOCAL_TIMEZONE) + time = time.replace(tzinfo=timezone) if time.tzinfo is None: msg = 'Could not parse timezone: ' + text