diff options
| author | Alex Schofield <git@ajschof.me> | 2026-05-04 21:18:15 +0100 |
|---|---|---|
| committer | Alex Schofield <git@ajschof.me> | 2026-05-04 21:18:15 +0100 |
| commit | 25d13201617acbbbb5adba1df6743b4b2c8562ee (patch) | |
| tree | be1bc611037bcc3b5d1b5877fe14312b42f1c1bc /fnme | |
| parent | 7a6c6bd36fd2651ca6cff7e2e3cb1b90df414100 (diff) | |
| download | fuelnearme-25d13201617acbbbb5adba1df6743b4b2c8562ee.tar.gz fuelnearme-25d13201617acbbbb5adba1df6743b4b2c8562ee.zip | |
preformat price strings before tabulate to avoid floatfmt/None issues
Diffstat (limited to 'fnme')
| -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(): |
