-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : 322 - list of locations (api) (#348)
* feat (partial): checks spreadsheet cities against placenames api. currently not properly set up to use list of cities * feat: prints out list of communities that we are looking for and a list of communities found with the api * chore: cleanup * removes extra line * chore: removes uneccessary line * chore: refines function , adds logic for missing names, moves feature types to constant * chore: fixes how communities are returned
- Loading branch information
Showing
5 changed files
with
71 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class FEATURES(): | ||
features_list = [ | ||
"Canadian Forces Base", | ||
"Canadian Forces Station", | ||
"City", | ||
"Community", | ||
"District Municipality (1)", | ||
"First Nation Village", | ||
"Former Locality", | ||
"Indian Government District", | ||
"Indian Government District : Land Unit", | ||
"Indian Reserve-Réserve indienne", | ||
"Locality", | ||
"Recreation Facility", | ||
"Recreational Community", | ||
"Region", | ||
"Regional District", | ||
"Resort Municipality", | ||
"Urban Community", | ||
"Village (1)", | ||
"Town" | ||
] |
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,34 @@ | ||
import requests | ||
from django.conf import settings | ||
from api.bcngws_constants import FEATURES | ||
|
||
|
||
def get_placename_matches(names_list, page_size, start_index, result): | ||
names_string = ", ".join(map(str, names_list)) | ||
|
||
query = { | ||
'outputFormat': 'json', | ||
'name': names_string, | ||
'itemsPerPage': 200, | ||
'startIndex': start_index, | ||
'exactSpelling': 0 | ||
} | ||
|
||
try: | ||
response = requests.get(settings.PLACENAMES_ENDPOINT, params=query) | ||
response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx) | ||
response = response.json() | ||
|
||
filtered_names = [ | ||
feature['properties']['name'] | ||
for feature in response['features'] | ||
if feature['properties']['featureType'] in FEATURES.features_list | ||
] | ||
|
||
result.extend(filtered_names) | ||
|
||
if response['properties']['totalResults'] >= start_index + page_size: | ||
get_placename_matches(names_list, page_size, start_index + page_size, result) | ||
|
||
except requests.RequestException as e: | ||
print(f"Error fetching data: {e}") |
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