From 48391ee8083c583909010c8e453bf9be0c094b6f Mon Sep 17 00:00:00 2001 From: Benjamin Sigonneau Date: Sat, 19 Nov 2022 22:13:54 +0100 Subject: [PATCH] Retrieve max_quantity and check if quantity belongs to interval This is because min_level was adjusted recently. Now we check if 500L and 1000L belongs to the given intervals, and we do not assum they are lower bounds of such intervals. --- fioul.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fioul.py b/fioul.py index 1f892ab..5b52b5d 100755 --- a/fioul.py +++ b/fioul.py @@ -20,6 +20,7 @@ def get_today_prices_from_internet(): pricesZone { price min_quantity + max_quantity } } } @@ -33,8 +34,14 @@ def get_today_prices_from_internet(): json_data = json_data["getProducts"][0] tax = float(json_data["tax"]["value"]) zones = json_data["pricesZone"] - price_500 = next((x["price"] for x in zones if x["min_quantity"] == 500), None) - price_1000 = next((x["price"] for x in zones if x["min_quantity"] == 1000), None) + price_500 = next( + (x["price"] for x in zones if x["min_quantity"] <= 500 < x["max_quantity"]), + None, + ) + price_1000 = next( + (x["price"] for x in zones if x["min_quantity"] <= 1000 < x["max_quantity"]), + None, + ) # apply tax price_500 = price_500 * (100 + tax) / 100.0 price_1000 = price_1000 * (100 + tax) / 100.0