Fixed PSN Profiles timezones
This commit is contained in:
parent
91e5562298
commit
6d1f23b1a0
|
@ -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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user