Download mcp/who.py from mgbam/MCP_Res: direct link, hf CLI and curl.
- Browser
- Download file 2.3 kB
-
https://huggingface.co/spaces/mgbam/MCP_Res/resolve/d3ef28f09426c4c4300a38bc46fb3ffa674e48c8/mcp/who.py
- Command line
-
hf download hf://spaces/mgbam/MCP_Res@d3ef28f09426c4c4300a38bc46fb3ffa674e48c8/mcp/who.py
-
curl -L -o who.py https://huggingface.co/spaces/mgbam/MCP_Res/resolve/d3ef28f09426c4c4300a38bc46fb3ffa674e48c8/mcp/who.py
2.3 kB
| #!/usr/bin/env python3 | |
| """WHO Global Health Observatory (GHO) async helper. | |
| Key features | |
| ------------ | |
| * **Essential medicines list** – `list_essential_medicines()` | |
| * **COVID‑19 country stats** – `fetch_covid_timeseries(iso_code)` | |
| * Built on `httpx.AsyncClient`, 20‑second timeout, no API‑key required. | |
| * Caches responses for 24 h in memory to spare quota. | |
| GHO OData API docs: https://www.who.int/data/gho/info/gho-odata-api | |
| """ | |
| from __future__ import annotations | |
| import httpx, asyncio, datetime | |
| from functools import lru_cache | |
| from typing import List, Dict | |
| BASE = "https://ghoapi.azureedge.net/api" | |
| # --------------------------------------------------------------------- | |
| # 📦 Essential medicines – EML endpoint | |
| # --------------------------------------------------------------------- | |
| async def list_essential_medicines() -> List[Dict]: | |
| """Return current WHO Model List of Essential Medicines (EML).""" | |
| url = f"{BASE}/EML" | |
| async with httpx.AsyncClient(timeout=20) as client: | |
| resp = await client.get(url) | |
| resp.raise_for_status() | |
| return resp.json().get("value", []) | |
| # --------------------------------------------------------------------- | |
| # 🦠 COVID‑19 time‑series by ISO country code | |
| # --------------------------------------------------------------------- | |
| COVID_DATASET = "COVID19CasesByCountries" | |
| async def fetch_covid_timeseries(iso_code: str) -> List[Dict]: | |
| """Return daily cases & deaths for given 3‑letter ISO code (e.g. 'USA').""" | |
| url = f"{BASE}/{COVID_DATASET}?$filter=Code%20eq%20'{iso_code.upper()}'" | |
| async with httpx.AsyncClient(timeout=20) as client: | |
| resp = await client.get(url) | |
| resp.raise_for_status() | |
| return resp.json().get("value", []) | |
| # --------------------------------------------------------------------- | |
| # Example CLI usage (for testing) – run: `python -m mcp.who` | |
| # --------------------------------------------------------------------- | |
| if __name__ == "__main__": | |
| async def _demo(): | |
| meds = await list_essential_medicines() | |
| print(f"Essential medicines fetched: {len(meds):,}") | |
| covid = await fetch_covid_timeseries("NGA") | |
| print(f"Nigeria COVID rows: {len(covid):,}") | |
| asyncio.run(_demo()) | |