From 6f5fc86c8ade11ab6d386cce43ed0ccafe6fe2ae Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 5 May 2022 22:01:08 +0100 Subject: [PATCH] Simplify date handling --- handler/lib/money.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/handler/lib/money.py b/handler/lib/money.py index 4553e0d..51914c2 100644 --- a/handler/lib/money.py +++ b/handler/lib/money.py @@ -9,7 +9,6 @@ import urllib3 import logging from elasticsearch import Elasticsearch from datetime import datetime -import builtins # Project imports from settings import settings @@ -377,14 +376,15 @@ class Money(util.Base): # Reformat the date how CoinGecko likes # 2022-05-02T11:17:14+00:00 - try: - date_parsed = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%S.%fZ") - except builtins.ValueError: + if "+" in created_at: date_split = created_at.split("+") date_split[1].replace(".", "") date_split[1].replace(":", "") created_at = "+".join(date_split) date_parsed = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%S%Z") + else: + date_parsed = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%S.%fZ") + date_formatted = date_parsed.strftime("%d-%m-%Y") # Get the historical rates for the right asset, extract the price