From 5a807ba7557792e78662064fa911abe04fa4b53d Mon Sep 17 00:00:00 2001 From: dsc Date: Sun, 24 Apr 2022 20:50:41 +0200 Subject: [PATCH] Fix historical fiat price API - fixes the historical fiat pricing on the History tab inside wowlet --- wowlet_backend/tasks/historical_prices.py | 14 ++++++++++++-- wowlet_backend/tasks/yellow.py | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/wowlet_backend/tasks/historical_prices.py b/wowlet_backend/tasks/historical_prices.py index 1ed0e44..89d11df 100644 --- a/wowlet_backend/tasks/historical_prices.py +++ b/wowlet_backend/tasks/historical_prices.py @@ -9,6 +9,7 @@ from typing import List, Union from datetime import datetime import aiofiles +from quart import current_app as app import settings from wowlet_backend.utils import httpget @@ -93,6 +94,15 @@ class HistoricalPriceTask(WowletTask): data filtered by the parameters.""" from wowlet_backend.factory import cache + # redis keys are always strings, convert input parameters + year = str(year) + if isinstance(month, int): + month = str(month) + + if not year.isnumeric() or (month and not month.isnumeric()): + app.logger.error(f"get() called with year: {year}, month {month}, not a number") + return + blob = await cache.get("historical_fiat") blob = json.loads(blob) if year not in blob: @@ -102,13 +112,13 @@ class HistoricalPriceTask(WowletTask): if not month: for _m, days in blob[year].items(): for day, price in days.items(): - rtn[datetime(year, _m, day).strftime('%Y%m%d')] = price + rtn[datetime(int(year), int(_m), int(day)).strftime('%Y%m%d')] = price return rtn if month not in blob[year]: return for day, price in blob[year][month].items(): - rtn[datetime(year, month, day).strftime('%Y%m%d')] = price + rtn[datetime(int(year), int(month), int(day)).strftime('%Y%m%d')] = price return rtn diff --git a/wowlet_backend/tasks/yellow.py b/wowlet_backend/tasks/yellow.py index 7b47852..6fc13c2 100644 --- a/wowlet_backend/tasks/yellow.py +++ b/wowlet_backend/tasks/yellow.py @@ -2,6 +2,7 @@ # Copyright (c) 2022, The Monero Project. # Copyright (c) 2022, dsc@xmr.pm +from typing import List from dateutil.parser import parse import settings @@ -21,7 +22,7 @@ class YellWowTask(WowletTask): self._http_endpoint = "https://yellow.wownero.com/api/user/" - async def task(self) -> list[dict]: + async def task(self) -> List[dict]: blob = await httpget(self._http_endpoint) if not isinstance(blob, list) or not blob: raise Exception(f"Invalid JSON response for {self._http_endpoint}")