Merge pull request 'Fix historical fiat price API' (#19) from fix-historical-fiat-price-api into master

Reviewed-on: #19
dsc 2 years ago
commit c7b187ebf1

@ -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")
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]:
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

@ -2,6 +2,7 @@
# Copyright (c) 2022, The Monero Project.
# Copyright (c) 2022,
from typing import List
from dateutil.parser import parse
import settings
@ -21,7 +22,7 @@ class YellWowTask(WowletTask):
self._http_endpoint = ""
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}")