Skip to content

Commit

Permalink
Add a script to fetch the list of countries #2559
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed May 26, 2022
1 parent 996db5c commit 437f4b0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions verification/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ mongo "mongodb://user:pass@some-connection-string/somedb" \

NOTE: For localhost (during dev) the DB connection string is "mongodb://localhost:27017/covid19" but for the atlas DB you have to use a proper connection string as the data service or curator services are doing on AWS.
You can go to the web atlas console and generate creds for you, they'll also show you the connection string to use those creds you just created.

# country_codes_map

This script is used to generate a list of the ISO-3166-2 alpha-2 country codes stored in the platform, along with the names recognised for each country. This augments the data dictionary by showing the countries that a user can expect to see, but also documenting those names that _aren't_ present (at time of writing, the country 'VA' is recognised as "Holy See" but not as "Vatican", for example).

Any user with an API key can run this script:

```shell
export GDOTH_API_BASEURL=<URL of the curator-service API, e.g. https://data-covid-19.global.health>
export GDOTH_API_KEY=<API key>
poetry run python3 country_codes_map.py
```
17 changes: 17 additions & 0 deletions verification/scripts/country_codes_map/country_codes_map.py
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'))
17 changes: 17 additions & 0 deletions verification/scripts/country_codes_map/pyproject.toml
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"

0 comments on commit 437f4b0

Please sign in to comment.