-
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.
Add a script to fetch the list of countries #2559
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 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
17 changes: 17 additions & 0 deletions
17
verification/scripts/country_codes_map/country_codes_map.py
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,17 @@ | ||
import codecs | ||
import json | ||
from os import environ | ||
import requests | ||
|
||
def retrieve_map(api_key: str, base_url: str) -> str: | ||
api_endpoint = f"{base_url}/api/geocode/countryNames" | ||
response = requests.get(api_endpoint, headers={ 'X-API-Key': api_key }) | ||
if response.ok: | ||
return response.json() | ||
else: | ||
raise ValueError(f"Got {response.status_code} response from server: {response.text}") | ||
|
||
if __name__ == '__main__': | ||
api_key = environ.get('GDOTH_API_KEY') | ||
base_url = environ.get('GDOTH_API_BASEURL') | ||
print(codecs.decode(json.dumps(retrieve_map(api_key, base_url), indent=4), 'unicode-escape')) |
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,17 @@ | ||
[tool.poetry] | ||
name = "country_codes_map" | ||
version = "0.1.0" | ||
description = "Generate a map of all the used country codes and their names" | ||
authors = ["Global.health <info@global.health>"] | ||
license = "MIT" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.9" | ||
requests = "^2.27.1" | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = "^7.1.2" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" |