[pre-commit.ci] pre-commit autoupdate (#12930)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.12.9 → v0.12.10](https://github.com/astral-sh/ruff-pre-commit/compare/v0.12.9...v0.12.10) - [github.com/pre-commit/mirrors-mypy: v1.15.0 → v1.17.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.15.0...v1.17.1) * Update word_break.py * Update word_break.py * Update word_break.py * Update word_break.py * Update word_break.py * Update covid_stats_via_xpath.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update pyproject.toml * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update pyproject.toml * Update pyproject.toml * Update covid_stats_via_xpath.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
This commit is contained in:
committed by
GitHub
parent
8c1c6c1763
commit
dc1b2003b4
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
This is to show simple COVID19 info fetching from worldometers site using lxml
|
||||
This is to show simple COVID19 info fetching from worldometers archive site using lxml
|
||||
* The main motivation to use lxml in place of bs4 is that it is faster and therefore
|
||||
more convenient to use in Python web projects (e.g. Django or Flask-based)
|
||||
"""
|
||||
@@ -19,12 +19,14 @@ from lxml import html
|
||||
|
||||
|
||||
class CovidData(NamedTuple):
|
||||
cases: int
|
||||
deaths: int
|
||||
recovered: int
|
||||
cases: str
|
||||
deaths: str
|
||||
recovered: str
|
||||
|
||||
|
||||
def covid_stats(url: str = "https://www.worldometers.info/coronavirus/") -> CovidData:
|
||||
def covid_stats(
|
||||
url: str = "https://web.archive.org/web/20250825095350/https://www.worldometers.info/coronavirus/",
|
||||
) -> CovidData:
|
||||
xpath_str = '//div[@class = "maincounter-number"]/span/text()'
|
||||
return CovidData(
|
||||
*html.fromstring(httpx.get(url, timeout=10).content).xpath(xpath_str)
|
||||
|
||||
Reference in New Issue
Block a user