1
0

Fixed PSN Profiles timezones
Some checks failed
Run Python tests (through Pytest) / Test (push) Failing after 34s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 29s

This commit is contained in:
Jon Michael Aanes 2024-11-24 19:07:09 +01:00
parent 91e5562298
commit 6d1f23b1a0
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
2 changed files with 5 additions and 5 deletions

View File

@ -21,6 +21,8 @@ URL_USER_GAME_TROPHIES = URL_API_ROOT + 'trophies/{game_id}/{psn_id}'
URL_GAMES_OVERVIEW = URL_API_ROOT + '{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: def game_psnprofiles_id_from_url(relative_url: str) -> int:
m = re.match(r'/(?:trophy|trophies)/(\d+)\-(?:[\w-]+)(/[\w-]*)?', relative_url) m = re.match(r'/(?:trophy|trophies)/(\d+)\-(?:[\w-]+)(/[\w-]*)?', relative_url)
result = m.group(1) result = m.group(1)
@ -195,7 +197,7 @@ class PsnProfiles(Scraper):
if 'Missing\nTimestamp' in cells[2].get_text().strip(): if 'Missing\nTimestamp' in cells[2].get_text().strip():
continue continue
cells[2].span.span.nobr.sup.extract() 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 { yield {
'game.name': game_name, 'game.name': game_name,

View File

@ -41,14 +41,12 @@ LOCAL_TIMEZONE = NOW.astimezone().tzinfo
def try_parse(text: str, fmt: str) -> datetime.datetime | None: def try_parse(text: str, fmt: str) -> datetime.datetime | None:
try: try:
time = datetime.datetime.strptime(text, fmt) # noqa: DTZ007 time = datetime.datetime.strptime(text, fmt) # noqa: DTZ007
if time.tzinfo is None:
time = time.replace(tzinfo=LOCAL_TIMEZONE)
except ValueError: except ValueError:
time = None time = None
return time 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.replace('\n', ' ')
text = text.strip() text = text.strip()
@ -62,7 +60,7 @@ def parse_time(text: str) -> datetime.datetime:
raise RuntimeError(msg) raise RuntimeError(msg)
if time.tzinfo is None: if time.tzinfo is None:
time = time.replace(tzinfo=LOCAL_TIMEZONE) time = time.replace(tzinfo=timezone)
if time.tzinfo is None: if time.tzinfo is None:
msg = 'Could not parse timezone: ' + text msg = 'Could not parse timezone: ' + text