generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit changes made by code formatters
- Loading branch information
1 parent
f4f6989
commit e36ecc3
Showing
3 changed files
with
28 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
from geopy import Nominatim | ||
from timezonefinder import TimezoneFinder | ||
|
||
|
||
def geocode(address) -> str: | ||
geolocator = Nominatim(user_agent="geocode") | ||
location = geolocator.geocode(address) | ||
try: | ||
latitude, longitude = location.latitude, location.longitude | ||
except ValueError: | ||
raise ValueError('geocode unable to find latitude & longitude for {address}'.format(address=address)) | ||
raise ValueError( | ||
'geocode unable to find latitude & longitude for {address}'.format(address=address)) | ||
return latitude, longitude | ||
|
||
|
||
def find_country_code(gps) -> tuple: | ||
latitude = gps[0] | ||
longitude = gps[1] | ||
geolocator = Nominatim(user_agent="geocode") | ||
location = geolocator.reverse([latitude, longitude]) | ||
country_code=location.raw['address']['country_code'] | ||
country_code = location.raw['address']['country_code'] | ||
|
||
return country_code.upper() | ||
|
||
|
||
def find_timezone(gps) -> tuple: | ||
tf_init = TimezoneFinder() | ||
latitude = gps[0] | ||
longitude = gps[1] | ||
try: | ||
timezone_name = tf_init.timezone_at(lat=latitude, lng=longitude) | ||
except ValueError: | ||
raise ValueError('The coordinates were out of bounds {latitude}:{longitude}'.format(lat=latitude,lng=longitude)) | ||
raise ValueError('The coordinates were out of bounds {latitude}:{longitude}'.format( | ||
lat=latitude, lng=longitude)) | ||
if timezone_name is None: | ||
raise ValueError('GPS coordinates did not match a time_zone') | ||
|
||
return timezone_name | ||
return timezone_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters