Return a dict of current worldwide COVID-19 statistics
(
url: str = "https://www.worldometers.info/coronavirus/",
)
| 18 | |
| 19 | |
| 20 | def 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 | |
| 36 | if __name__ == "__main__": |
no test coverage detected