-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15f35e4
commit b2dff0d
Showing
7 changed files
with
85 additions
and
23 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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
import logging | ||
from python.common.models import City | ||
|
||
|
||
def get_city_name(city_code, args) -> str: | ||
application = args.get('app') | ||
db = args.get('db') | ||
with application.app_context(): | ||
city_data = db.session.query(City) \ | ||
.filter(City.objectCd == city_code) \ | ||
.all() | ||
if len(city_data) == 0: | ||
logging.error("city not found") | ||
else: | ||
return city_data[0].objectDsc |
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
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import logging | ||
import requests | ||
from python.form_handler.config import Config | ||
|
||
geocoding_url = Config.GEOCODING_API_URL | ||
geocoding_key = Config.GEOCODING_API_KEY | ||
|
||
|
||
def get_coordinates(address: str, city: str)-> tuple: | ||
logging.debug(f'Getting coordinates for address: {address} and city: {city}') | ||
|
||
url = f'{geocoding_url}/coordinates?address={address}&city={city}' | ||
logging.debug(f'Geocoding API URL: {url}') | ||
response = requests.get(url, headers={'api-key': geocoding_key}) | ||
if response.status_code == 200: | ||
get_coordinates_response = response.json() | ||
if get_coordinates_response['province'] != 'BC': | ||
logging.warning(f'Coordinates found for address: {address} and city: {city} but not in BC') | ||
return False, None, None | ||
return True, get_coordinates_response['latitude'], get_coordinates_response['longitude'] | ||
elif response.status_code == 404: | ||
logging.warning(f'No coordinates found for address: {address} and city: {city}') | ||
return False, None, None | ||
else: | ||
raise Exception(f'Error getting coordinates for address: {address} and city: {city} -> Status: {response.status_code} Response: {response.text}') |