Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion web_programming/world_covid19_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,32 @@

def world_covid19_stats(url: str = "https://www.worldometers.info/coronavirus") -> dict:
"""
Return a dict of current worldwide COVID-19 statistics
Return a dict of current worldwide COVID-19 statistics.

The function scrapes data from the Worldometer website and returns the
global COVID-19 statistics.

Args:
url (str): The URL to fetch the COVID-19 data from.

Returns:
dict: A dictionary of worldwide COVID-19 statistics where the keys are
the names of the statistics (e.g., 'Total Cases') and the values are the
corresponding numbers (e.g., '233,456,789').

Example:
>>> stats = world_covid19_stats()
>>> isinstance(stats, dict)
True
>>> 'Total Cases' in stats.keys()
True
>>> 'Total Deaths' in stats.keys()
True
>>> len(stats) > 0
True

Raises:
requests.RequestException: If there is an issue with the network request.
"""
soup = BeautifulSoup(requests.get(url, timeout=10).text, "html.parser")
keys = soup.findAll("h1")
Expand Down
Loading