MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / world_covid19_stats

Function world_covid19_stats

web_programming/world_covid19_stats.py:20–33  ·  view source on GitHub ↗

Return a dict of current worldwide COVID-19 statistics

(
    url: str = "https://www.worldometers.info/coronavirus/",
)

Source from the content-addressed store, hash-verified

18
19
20def world_covid19_stats(
21 url: str = "https://www.worldometers.info/coronavirus/",
22) -> dict:
23 """
24 Return a dict of current worldwide COVID-19 statistics
25 """
26 soup = BeautifulSoup(
27 httpx.get(url, timeout=10, follow_redirects=True).text, "html.parser"
28 )
29 keys = soup.find_all("h1")
30 values = soup.find_all("div", {"class": "maincounter-number"})
31 keys += soup.find_all("span", {"class": "panel-title"})
32 values += soup.find_all("div", {"class": "number-table-main"})
33 return {key.text.strip(): value.text.strip() for key, value in zip(keys, values)}
34
35
36if __name__ == "__main__":

Callers 1

Calls 1

getMethod · 0.45

Tested by

no test coverage detected