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)