From 5d88485c4861cc67095dddb028d753db30d8296d Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sat, 11 Jan 2025 15:15:46 -0600 Subject: [PATCH] Add offline mode support to fx.get_rates() --- agenda/fx.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/agenda/fx.py b/agenda/fx.py index 737b43a..de70146 100644 --- a/agenda/fx.py +++ b/agenda/fx.py @@ -85,7 +85,9 @@ def get_rates(config: flask.config.Config) -> dict[str, Decimal]: delta = now - recent full_path = os.path.join(fx_dir, recent_filename) - if recent_filename.endswith(file_suffix) and delta < timedelta(hours=12): + if recent_filename.endswith(file_suffix) and ( + delta < timedelta(hours=12) or config["OFFLINE_MODE"] + ): return read_cached_rates(full_path, currencies) url = "http://api.exchangerate.host/live"