From 3308261372caf92751b322597bdf06c479cef70a Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 11 Jul 2024 16:17:38 -0400 Subject: [PATCH] fixed gasnow cache when no data from api --- core.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core.py b/core.py index d844137..e776208 100755 --- a/core.py +++ b/core.py @@ -368,19 +368,20 @@ def get_beacon_gas_prices(speed=None, cache_interval_seconds=10): gas = {} if os.path.isfile(gasnow_file := "{}/gasnow.json".format(cache_folder)): gas = json.load(open(gasnow_file)) - if not gas or (gas['data']['timestamp'] / 1000) + cache_interval_seconds < time.time(): + if not gas or not gas['data'] or (gas['data']['timestamp'] / 1000) + cache_interval_seconds < time.time(): try: r = requests.get('https://beacon.pulsechain.com/api/v1/execution/gasnow') - gas = r.json() + _gas = r.json() except Exception as e: if not gas: logging.debug(e) - return None + return 5555 * 10 ** 369 else: - if not gas: + if not _gas and not gas: logging.debug("No gas data returned from GasNow API endpoint") - return None - else: + return 5555 * 10 ** 369 + elif _gas['data']: + gas = _gas open('./data/cache/gasnow.json', 'w').write(json.dumps(gas, indent=4)) if type(speed) is str: try: