From 79e8f8e76fd18a45a7f513b952261cc7d1a4fee9 Mon Sep 17 00:00:00 2001 From: Alex Schofield Date: Mon, 27 Apr 2026 09:37:15 +0100 Subject: improve sort function to handle N/A fuel prices --- main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index f092eeb..ae842f4 100644 --- a/main.py +++ b/main.py @@ -67,13 +67,16 @@ def filter_df(dframe, arguments, loc): "e10_price": round(e10_price / 100, 2), "diesel_price": round(diesel_price / 100, 2), } - near_stations.append(station_dict) + na_dict = { + k: (v if v != 0.00 else "N/A") for (k, v) in station_dict.items() + } + near_stations.append(na_dict) return near_stations def sort_stations(stations: list[dict], sort: str) -> list[dict]: sort_key = SORT_KV.get(sort) - return sorted(stations, key=lambda d: d[sort_key]) + return sorted(stations, key=lambda d: d[sort_key] if d[sort_key] != "N/A" else 999) def output_stations(stations): -- cgit v1.2.3