mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-05-18 23:21:28 +00:00
* Replace dependency `requests` with `httpx` Fixes #12742 Signed-off-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> * updating DIRECTORY.md * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> Co-authored-by: Lim, Lukaz Wei Hwang <lukaz.wei.hwang.lim@intel.com> Co-authored-by: cclauss <cclauss@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""
|
|
Provide the current worldwide COVID-19 statistics.
|
|
This data is being scrapped from 'https://www.worldometers.info/coronavirus/'.
|
|
"""
|
|
|
|
# /// script
|
|
# requires-python = ">=3.13"
|
|
# dependencies = [
|
|
# "beautifulsoup4",
|
|
# "httpx",
|
|
# ]
|
|
# ///
|
|
|
|
import httpx
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
def world_covid19_stats(
|
|
url: str = "https://www.worldometers.info/coronavirus/",
|
|
) -> dict:
|
|
"""
|
|
Return a dict of current worldwide COVID-19 statistics
|
|
"""
|
|
soup = BeautifulSoup(
|
|
httpx.get(url, timeout=10, follow_redirects=True).text, "html.parser"
|
|
)
|
|
keys = soup.find_all("h1")
|
|
values = soup.find_all("div", {"class": "maincounter-number"})
|
|
keys += soup.find_all("span", {"class": "panel-title"})
|
|
values += soup.find_all("div", {"class": "number-table-main"})
|
|
return {key.text.strip(): value.text.strip() for key, value in zip(keys, values)}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("\033[1m COVID-19 Status of the World \033[0m\n")
|
|
print("\n".join(f"{key}\n{value}" for key, value in world_covid19_stats().items()))
|