mirror of
https://git.wownero.com/wowlet/wowlet-backend.git
synced 2024-08-15 01:03:13 +00:00
Fix historical fiat price API - fixes the historical fiat pricing on the History tab inside wowlet
This commit is contained in:
parent
7faf59c31d
commit
5a807ba755
2 changed files with 14 additions and 3 deletions
|
@ -9,6 +9,7 @@ from typing import List, Union
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import aiofiles
|
import aiofiles
|
||||||
|
from quart import current_app as app
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
from wowlet_backend.utils import httpget
|
from wowlet_backend.utils import httpget
|
||||||
|
@ -93,6 +94,15 @@ class HistoricalPriceTask(WowletTask):
|
||||||
data filtered by the parameters."""
|
data filtered by the parameters."""
|
||||||
from wowlet_backend.factory import cache
|
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 = await cache.get("historical_fiat")
|
||||||
blob = json.loads(blob)
|
blob = json.loads(blob)
|
||||||
if year not in blob:
|
if year not in blob:
|
||||||
|
@ -102,13 +112,13 @@ class HistoricalPriceTask(WowletTask):
|
||||||
if not month:
|
if not month:
|
||||||
for _m, days in blob[year].items():
|
for _m, days in blob[year].items():
|
||||||
for day, price in days.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
|
return rtn
|
||||||
|
|
||||||
if month not in blob[year]:
|
if month not in blob[year]:
|
||||||
return
|
return
|
||||||
|
|
||||||
for day, price in blob[year][month].items():
|
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
|
return rtn
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# Copyright (c) 2022, The Monero Project.
|
# Copyright (c) 2022, The Monero Project.
|
||||||
# Copyright (c) 2022, dsc@xmr.pm
|
# Copyright (c) 2022, dsc@xmr.pm
|
||||||
|
|
||||||
|
from typing import List
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
|
@ -21,7 +22,7 @@ class YellWowTask(WowletTask):
|
||||||
|
|
||||||
self._http_endpoint = "https://yellow.wownero.com/api/user/"
|
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)
|
blob = await httpget(self._http_endpoint)
|
||||||
if not isinstance(blob, list) or not blob:
|
if not isinstance(blob, list) or not blob:
|
||||||
raise Exception(f"Invalid JSON response for {self._http_endpoint}")
|
raise Exception(f"Invalid JSON response for {self._http_endpoint}")
|
||||||
|
|
Loading…
Reference in a new issue