Catch exceptions when updating gauge values

This commit is contained in:
Kumi 2022-10-24 14:28:01 +00:00
parent 2ddefe1154
commit b59707d3a7
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -153,17 +153,20 @@ start_http_server(8090)
while True:
for gauge, aks in gauges:
offers: List[dict] = aks.get_offers()
available_offers: List[dict] = filter(
lambda x: x["stock"] == "InStock", offers)
store: Optional[str]
if (store := settings.get("Store", fallback=defaults.get("Store", ""))):
try:
offers: List[dict] = aks.get_offers()
available_offers: List[dict] = filter(
lambda x: x["platform"] == store, available_offers)
lambda x: x["stock"] == "InStock", offers)
store: Optional[str]
best_offer: dict = min(
available_offers, key=lambda x: x["price"][currency]["price"])
gauge.set(best_offer["price"][currency]["price"])
if (store := settings.get("Store", fallback=defaults.get("Store", ""))):
available_offers: List[dict] = filter(
lambda x: x["platform"] == store, available_offers)
best_offer: dict = min(
available_offers, key=lambda x: x["price"][currency]["price"])
gauge.set(best_offer["price"][currency]["price"])
except Exception as e:
print(f"Error updating gauge value for {gauge._name}: {e}")
time.sleep(60)