mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-25 23:33:58 +01:00
prevent oops in future
This commit is contained in:
parent
f87be092a5
commit
8b11b75c11
|
@ -149,8 +149,9 @@ async def run_checks(incoming_request: fastapi.Request):
|
||||||
async def get_crypto_price(cryptocurrency: str) -> float:
|
async def get_crypto_price(cryptocurrency: str) -> float:
|
||||||
"""Gets the price of a cryptocurrency using coinbase's API."""
|
"""Gets the price of a cryptocurrency using coinbase's API."""
|
||||||
|
|
||||||
|
cache_path = os.path.join('cache', 'crypto_prices.json')
|
||||||
try:
|
try:
|
||||||
async with aiofiles.open(os.path.join('cache', 'crypto_prices.json')) as f:
|
async with aiofiles.open(cache_path) as f:
|
||||||
content = await f.read()
|
content = await f.read()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
cache = {}
|
cache = {}
|
||||||
|
@ -167,7 +168,7 @@ async def get_crypto_price(cryptocurrency: str) -> float:
|
||||||
cache[cryptocurrency] = usd_price
|
cache[cryptocurrency] = usd_price
|
||||||
cache['_last_updated'] = time.time()
|
cache['_last_updated'] = time.time()
|
||||||
|
|
||||||
async with aiofiles.open(os.path.join('cache', 'crypto_prices.json'), 'w') as f:
|
async with aiofiles.open(cache_path, 'w') as f:
|
||||||
for chunk in json.JSONEncoder().iterencode(cache):
|
for chunk in json.JSONEncoder().iterencode(cache):
|
||||||
await f.write(chunk)
|
await f.write(chunk)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue