diff options
| author | Alex Schofield <git@ajschof.me> | 2026-04-24 22:07:23 +0100 |
|---|---|---|
| committer | Alex Schofield <git@ajschof.me> | 2026-04-24 22:07:23 +0100 |
| commit | fcb7904d6a2a28fc81a731572eda42d5b60b1d15 (patch) | |
| tree | cbe710ca637dd9e67e3c4f7495b650ad7b0dbaed | |
| parent | 54b7a10c0343e882d20297bd5dbdd8930fda4191 (diff) | |
| download | fuelnearme-fcb7904d6a2a28fc81a731572eda42d5b60b1d15.tar.gz fuelnearme-fcb7904d6a2a28fc81a731572eda42d5b60b1d15.zip | |
refactor get_location() to use type hints and instance checks
| -rw-r--r-- | main.py | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -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(): |
