From fcb7904d6a2a28fc81a731572eda42d5b60b1d15 Mon Sep 17 00:00:00 2001 From: Alex Schofield Date: Fri, 24 Apr 2026 22:07:23 +0100 Subject: refactor get_location() to use type hints and instance checks --- main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index 797f9b8..7265e81 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,7 @@ import requests from colorama import Fore, Style from geopy.distance import geodesic from geopy.geocoders import Nominatim +from geopy.location import Location ENDPOINT = "https://www.fuel-finder.service.gov.uk/internal/v1.0.2/csv/get-latest-fuel-prices-csv" @@ -20,15 +21,13 @@ def parse_args() -> argparse.Namespace: return parser.parse_args() -def get_location(address): - loc = Nominatim(user_agent="FuelNearMe") - getLoc = loc.geocode(address) - if not getLoc: +def get_location(address: str) -> tuple[float, float]: + geolocator = Nominatim(user_agent="FuelNearMe") + result = geolocator.geocode(address) + if not isinstance(result, Location): print("[*] Failed to get location. Please check if the address is valid.") sys.exit(1) - latitude = getLoc.latitude - longitude = getLoc.longitude - return (latitude, longitude) + return (result.latitude, result.longitude) def get_latest_data(): -- cgit v1.2.3