From ac7a76a1de16fc7a87b392edbb0d8e4da4bf2cd3 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 5 May 2022 21:55:17 +0100 Subject: [PATCH] Fix date handling --- handler/lib/money.py | 12 ++++++++++-- handler/util.py | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/handler/lib/money.py b/handler/lib/money.py index 2d10a66..4553e0d 100644 --- a/handler/lib/money.py +++ b/handler/lib/money.py @@ -9,6 +9,7 @@ import urllib3 import logging from elasticsearch import Elasticsearch from datetime import datetime +import builtins # Project imports from settings import settings @@ -194,7 +195,7 @@ class Money(util.Base): "profit_usd": profit, } - self.tx.write_to_es("get_profit", cast_es) + self.write_to_es("get_profit", cast_es) return profit @inlineCallbacks @@ -376,7 +377,14 @@ class Money(util.Base): # Reformat the date how CoinGecko likes # 2022-05-02T11:17:14+00:00 - date_parsed = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%S.%fZ") + try: + date_parsed = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%S.%fZ") + except builtins.ValueError: + 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") date_formatted = date_parsed.strftime("%d-%m-%Y") # Get the historical rates for the right asset, extract the price diff --git a/handler/util.py b/handler/util.py index c7fba26..bb7870d 100644 --- a/handler/util.py +++ b/handler/util.py @@ -122,8 +122,8 @@ def last_online_recent(date): # for LBTC # 2022-04-16T08:53:58+00:00 date_split = date.split("+") - date[1].replace(".", "") - date[1].replace(":", "") + date_split[1].replace(".", "") + date_split[1].replace(":", "") date = "+".join(date_split) date_string = "%Y-%m-%dT%H:%M:%S%z" now = datetime.now(timezone.utc)