diff options
| -rw-r--r-- | fnme/cli.py | 15 | ||||
| -rw-r--r-- | fnme/station.py | 16 |
2 files changed, 24 insertions, 7 deletions
diff --git a/fnme/cli.py b/fnme/cli.py index 203391c..3d7d72e 100644 --- a/fnme/cli.py +++ b/fnme/cli.py @@ -15,14 +15,20 @@ _PRICE_COLS = { "diesel_price": "B7S (£/L)", } -_HEADERS = {"station_name": "Station Name", "distance": "Distance (mi)", **_PRICE_COLS} +_HEADERS = { + "station_name": "Station Name", + "distance": "Distance (mi)", + **_PRICE_COLS, +} def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser() parser.add_argument("-a", "--address", type=str, required=True) parser.add_argument("-r", "--radius", type=int, default=5) - parser.add_argument("-s", "--sort", type=str, default="e10", choices=SORT_KV.keys()) + parser.add_argument( + "-s", "--sort", type=str, default="e10", choices=SORT_KV.keys() + ) return parser.parse_args() @@ -35,7 +41,10 @@ def output_stations(stations: List[Dict[str, Any]]) -> None: print("[*] No stations found.") return - rows = [{**s, **{col: _fmt_price(s[col]) for col in _PRICE_COLS}} for s in stations] + rows = [ + {**s, **{col: _fmt_price(s[col]) for col in _PRICE_COLS}} + for s in stations + ] print(tabulate(rows, headers=_HEADERS, floatfmt="1.f")) diff --git a/fnme/station.py b/fnme/station.py index 94d965a..6f5427a 100644 --- a/fnme/station.py +++ b/fnme/station.py @@ -16,8 +16,12 @@ def _bounding_box( deg_lat = rad / 69.0 deg_lon = rad / (69.0 * math.cos(math.radians(lat))) return dframe[ - dframe["forecourts.location.latitude"].between(lat - deg_lat, lat + deg_lat) - & dframe["forecourts.location.longitude"].between(lon - deg_lon, lon + deg_lon) + dframe["forecourts.location.latitude"].between( + lat - deg_lat, lat + deg_lat + ) + & dframe["forecourts.location.longitude"].between( + lon - deg_lon, lon + deg_lon + ) ] @@ -29,7 +33,10 @@ def _haversine_miles( lat2, lon2 = np.radians(lat2), np.radians(lon2) dlat = lat2 - lat1 dlon = lon2 - lon1 - a = np.sin(dlat / 2) ** 2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon / 2) ** 2 + a = ( + np.sin(dlat / 2) ** 2 + + np.cos(lat1) * np.cos(lat2) * np.sin(dlon / 2) ** 2 + ) return R * 2 * np.arcsin(np.sqrt(a)) @@ -73,5 +80,6 @@ def process_stations( def sort_stations(stations: list[dict], sort: str) -> list[dict]: sort_key = SORT_KV[sort] return sorted( - stations, key=lambda d: d[sort_key] if d[sort_key] is not None else float("inf") + stations, + key=lambda d: d[sort_key] if d[sort_key] is not None else float("inf"), ) |
