From 8b11b75c11ee35e10cd99ccfb9aa7c17daf15109 Mon Sep 17 00:00:00 2001 From: monosans Date: Fri, 6 Oct 2023 10:53:22 +0300 Subject: [PATCH] prevent oops in future --- api/core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/core.py b/api/core.py index 4312db9..059b122 100644 --- a/api/core.py +++ b/api/core.py @@ -149,8 +149,9 @@ async def run_checks(incoming_request: fastapi.Request): async def get_crypto_price(cryptocurrency: str) -> float: """Gets the price of a cryptocurrency using coinbase's API.""" + cache_path = os.path.join('cache', 'crypto_prices.json') 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() except FileNotFoundError: cache = {} @@ -167,7 +168,7 @@ async def get_crypto_price(cryptocurrency: str) -> float: cache[cryptocurrency] = usd_price 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): await f.write(chunk)