Skip to content

Commit

Permalink
Script to fetch country codes #2559
Browse files Browse the repository at this point in the history
Would work, if not for the mongo perf issues
  • Loading branch information
iamleeg committed Mar 17, 2022
1 parent e92a8c1 commit 781db6a
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 1 deletion.
9 changes: 8 additions & 1 deletion verification/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ 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.
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.

## Generating list of country codes

The script `country_codes_map` uses the curator service to generate a list of country codes found in the case data, and any of the names that we would display or parse from ingestion scripts for each country. You need to set two environment variables:

- `GDOTH_API_BASEURL` is the base URL for the Global.health instance API: e.g. `https://data.covid-19.global.health/`
- `GDOTH_API_KEY` is the API key for a user (any user, no specific roles needed) on that instance
16 changes: 16 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,16 @@
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(json.dumps(retrieve_map(api_key, base_url), indent=4))
233 changes: 233 additions & 0 deletions verification/scripts/country_codes_map/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions verification/scripts/country_codes_map/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[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>"]

[tool.poetry.dependencies]
python = "^3.9"
requests = "^2.27.1"

[tool.poetry.dev-dependencies]
pytest = "^5.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 781db6a

Please sign in to comment.