MCPcopy
hub / github.com/fluentpython/example-code-2e / get_country

Function get_country

20-executors/getflags/flags3_asyncio.py:33–40  ·  view source on GitHub ↗
(client: httpx.AsyncClient,
                      base_url: str,
                      cc: str)

Source from the content-addressed store, hash-verified

31
32# tag::FLAGS3_ASYNCIO_GET_COUNTRY[]
33async def get_country(client: httpx.AsyncClient,
34 base_url: str,
35 cc: str) -> str: # <1>
36 url = f'{base_url}/{cc}/metadata.json'.lower()
37 resp = await client.get(url, timeout=3.1, follow_redirects=True)
38 resp.raise_for_status()
39 metadata = resp.json() # <2>
40 return metadata['country'] # <3>
41# end::FLAGS3_ASYNCIO_GET_COUNTRY[]
42
43# tag::FLAGS3_ASYNCIO_DOWNLOAD_ONE[]

Callers 1

download_oneFunction · 0.85

Calls 2

jsonMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected