Account for LBTC time formats

This commit is contained in:
Mark Veidemanis 2022-04-18 17:22:47 +01:00
parent ddee10958f
commit 9b3f36cc44
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 13 additions and 3 deletions

View File

@ -1,6 +1,6 @@
# Other library imports
from httpx import ReadTimeout, ReadError, RemoteProtocolError
from datetime import datetime
from datetime import datetime, timezone
import logging
# Project imports
@ -115,8 +115,18 @@ def last_online_recent(date):
:return: bool indicating whether the date was recent enough
:rtype: bool
"""
date_parsed = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ")
now = datetime.now()
if "+" in date:
# for LBTC
# 2022-04-16T08:53:58+00:00
date_split = date.split("+")
date[1].replace(".", "")
date[1].replace(":", "")
date = "+".join(date_split)
date_string = "%Y-%m-%dT%H:%M:%S%z"
else:
date_string = "%Y-%m-%dT%H:%M:%S.%fZ"
date_parsed = datetime.strptime(date, date_string)
now = datetime.now(timezone.utc)
sec_ago_date = (now - date_parsed).total_seconds()
return sec_ago_date < 172800