From f6b565226862ec1539ab5c0181127bb6d22a7d96 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 21 Nov 2022 07:20:12 +0000 Subject: [PATCH] Update Drakdoo API format --- core/lib/schemas/drakdoo_s.py | 1 + core/views/hooks.py | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/core/lib/schemas/drakdoo_s.py b/core/lib/schemas/drakdoo_s.py index 34b51ea..961c1da 100644 --- a/core/lib/schemas/drakdoo_s.py +++ b/core/lib/schemas/drakdoo_s.py @@ -17,5 +17,6 @@ class DrakdooCallback(BaseModel): title: str message: str period: str + price: str market: DrakdooMarket timestamp: DrakdooTimestamp diff --git a/core/views/hooks.py b/core/views/hooks.py index c710131..f229644 100644 --- a/core/views/hooks.py +++ b/core/views/hooks.py @@ -1,4 +1,4 @@ -import re +# import re import orjson from django.contrib.auth.mixins import LoginRequiredMixin @@ -17,16 +17,16 @@ from core.views import ObjectCreate, ObjectDelete, ObjectList, ObjectUpdate log = logs.get_logger(__name__) -def extract_price(message): - result = re.findall("\d+\.\d+", message) # noqa - if len(result) != 1: - log.error(f"Could not extract price from message: {message}") - return False - try: - log.debug(f"Extracted {result[0]} from '{message}'") - return float(result[0]) - except ValueError: - return False +# def extract_price(message): +# result = re.findall("\d+\.\d+", message) # noqa +# if len(result) != 1: +# log.error(f"Could not extract price from message: {message}") +# return False +# try: +# log.debug(f"Extracted {result[0]} from '{message}'") +# return float(result[0]) +# except ValueError: +# return False class HookAPI(APIView): @@ -48,9 +48,14 @@ class HookAPI(APIView): log.error(f"HookAPI POST: {e}") return HttpResponseBadRequest(e) - price = extract_price(hook_resp.message) - if not price: - log.debug(f"Could not extract price from message: {hook_resp.message}") + # price = extract_price(hook_resp.message) + # if not price: + # log.debug(f"Could not extract price from message: {hook_resp.message}") + # return HttpResponseBadRequest("Could not extract price from message") + try: + price = float(hook_resp.market.price) + except ValueError: + log.debug(f"Could not extract price from message: {hook_resp.market.price}") return HttpResponseBadRequest("Could not extract price from message") base = hook_resp.market.item quote = hook_resp.market.currency