aboutsummaryrefslogtreecommitdiffstats
path: root/fnme/cli.py
diff options
context:
space:
mode:
authorAlex Schofield <git@ajschof.me>2026-05-03 18:31:26 +0100
committerAlex Schofield <git@ajschof.me>2026-05-03 18:31:26 +0100
commitd0e905285691d73f2cf7e45a88dbadf631620f0a (patch)
tree3de262bd346732f8813252e8cf38c379cbd1d250 /fnme/cli.py
parente6b342749ea516c536973b828b5f5eef951b4796 (diff)
downloadfuelnearme-d0e905285691d73f2cf7e45a88dbadf631620f0a.tar.gz
fuelnearme-d0e905285691d73f2cf7e45a88dbadf631620f0a.zip
move all logic into fnme folder
Diffstat (limited to 'fnme/cli.py')
-rw-r--r--fnme/cli.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/fnme/cli.py b/fnme/cli.py
index e69de29..d93d9f4 100644
--- a/fnme/cli.py
+++ b/fnme/cli.py
@@ -0,0 +1,59 @@
+import argparse
+import sys
+from typing import Any, Dict, List
+
+from constants import SORT_KV
+from data import get_latest_data
+from geo import get_location
+from station import filter_df, sort_stations
+from tabulate import tabulate
+
+
+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())
+ return parser.parse_args()
+
+
+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",
+ )
+ )
+
+
+def main():
+ args = parse_args()
+
+ try:
+ location = get_location(args.address)
+ except ValueError as e:
+ print(f"[*] {e}")
+ sys.exit(1)
+ df, last_modified = get_latest_data()
+
+ print(f"Last updated: {last_modified}")
+
+ df_filtered = filter_df(df, args, location)
+
+ sorted_stations_list = sort_stations(df_filtered, args.sort)
+
+ output_stations(sorted_stations_list)
+
+
+if __name__ == "__main__":
+ main()
git.ajschof.me — hosted by ajschofield — powered by cgit