From 9b3f36cc442b5262da02202f75904fcdfa74c2b8 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 18 Apr 2022 17:22:47 +0100 Subject: [PATCH] Account for LBTC time formats --- handler/util.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/handler/util.py b/handler/util.py index 3e143e0..d589592 100644 --- a/handler/util.py +++ b/handler/util.py @@ -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