diff options
| -rw-r--r-- | fnme/cli.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/fnme/cli.py b/fnme/cli.py index aa49ec1..203391c 100644 --- a/fnme/cli.py +++ b/fnme/cli.py @@ -9,6 +9,14 @@ from fnme.data import get_latest_data from fnme.geo import get_location from fnme.station import process_stations, sort_stations +_PRICE_COLS = { + "e5_price": "E5 (£/L)", + "e10_price": "E10 (£/L)", + "diesel_price": "B7S (£/L)", +} + +_HEADERS = {"station_name": "Station Name", "distance": "Distance (mi)", **_PRICE_COLS} + def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser() @@ -18,23 +26,18 @@ def parse_args() -> argparse.Namespace: return parser.parse_args() +def _fmt_price(v: float | None) -> str: + return f"{v:.2f}" if v is not None else "N/A" + + def output_stations(stations: List[Dict[str, Any]]) -> None: if not stations: print("[*] No stations found.") return - print( - tabulate( - stations, - headers={ - "station_name": "Station Name", - "distance": "Distance (miles)", - "e5_price": "E5 (£/L)", - "e10_price": "E10 (£/L)", - "diesel_price": "B7S (£/L)", - }, - floatfmt=".2f", - ) - ) + + rows = [{**s, **{col: _fmt_price(s[col]) for col in _PRICE_COLS}} for s in stations] + + print(tabulate(rows, headers=_HEADERS, floatfmt="1.f")) def main(): |
