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

Reviewed-on: https://git.wownero.com/wowlet/wowlet-backend/pulls/19
This commit is contained in:
dsc 2022-04-24 19:13:44 +00:00
commit c7b187ebf1
2 changed files with 14 additions and 3 deletions

View file

@ -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

View file

@ -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}")