Convert prices to GBP and show

Closes: #120
This commit is contained in:
Edward Betts 2024-04-20 07:54:16 +01:00
parent dbc12adb3d
commit 5ab9d93484
3 changed files with 32 additions and 6 deletions

View file

@ -44,11 +44,11 @@ async def get_gbpusd(config: flask.config.Config) -> Decimal:
return typing.cast(Decimal, 1 / data["quotes"]["USDGBP"])
def get_exchange_rates(config) -> dict[str, Decimal]:
def get_rates(config: flask.config.Config) -> dict[str, Decimal]:
"""Get current values of exchange rates for a list of currencies against GBP."""
currencies = config.CURRENCIES
access_key = config.EXCHANGERATE_ACCESS_KEY
data_dir = config.DATA_DIR
currencies = config["CURRENCIES"]
access_key = config["EXCHANGERATE_ACCESS_KEY"]
data_dir = config["DATA_DIR"]
now = datetime.now()
now_str = now.strftime("%Y-%m-%d_%H:%M")
@ -65,7 +65,7 @@ def get_exchange_rates(config) -> dict[str, Decimal]:
recent = datetime.strptime(recent_filename[:16], "%Y-%m-%d_%H:%M")
delta = now - recent
if delta < timedelta(hours=6):
if delta < timedelta(hours=12):
full_path = os.path.join(fx_dir, recent_filename)
with open(full_path) as file:
data = json.load(file, parse_float=Decimal)