Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a script to fetch the list of countries #2559 #2710

Merged
merged 2 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
iamleeg marked this conversation as resolved.
Show resolved Hide resolved
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"