diff --git a/web_programming/world_covid19_stats.py b/web_programming/world_covid19_stats.py index 4948d8cfd43c..6dbe9f4409af 100644 --- a/web_programming/world_covid19_stats.py +++ b/web_programming/world_covid19_stats.py @@ -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")