Skip to content

Commit 5a4a6a5

Browse files
codedbyasimpre-commit-ci[bot]cclauss
authored
Update .pre-commit-config.yaml to reflect current linting and formatt… (TheAlgorithms#12841)
* Update .pre-commit-config.yaml to reflect current linting and formatting setup - Replaced outdated references to `black` with the actual tools used in the repo: `ruff` and `ruff-format`. - Ensured all configured hooks are up to date and relevant to Python development. - This aligns the linting and formatting setup with the project's actual pre-commit pipeline. - Improves consistency for contributors by preventing confusion between formatting tools. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * We use httpx, not requests * response = httpx.get(request_url, timeout=10).raise_for_status() --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent ed7c9b5 commit 5a4a6a5

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
- repo: https://github.com/astral-sh/ruff-pre-commit
1919
rev: v0.11.11
2020
hooks:
21-
- id: ruff
21+
- id: ruff-check
2222
- id: ruff-format
2323

2424
- repo: https://github.com/codespell-project/codespell
@@ -29,7 +29,7 @@ repos:
2929
- tomli
3030

3131
- repo: https://github.com/tox-dev/pyproject-fmt
32-
rev: "v2.6.0"
32+
rev: v2.6.0
3333
hooks:
3434
- id: pyproject-fmt
3535

@@ -53,12 +53,11 @@ repos:
5353
args:
5454
- --explicit-package-bases
5555
- --ignore-missing-imports
56-
- --install-types # See mirrors-mypy README.md
56+
- --install-types
5757
- --non-interactive
58-
additional_dependencies: [types-requests]
5958

6059
- repo: https://github.com/pre-commit/mirrors-prettier
61-
rev: "v4.0.0-alpha.8"
60+
rev: v4.0.0-alpha.8
6261
hooks:
6362
- id: prettier
6463
types_or: [toml, yaml]

web_programming/fetch_well_rx_price.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@
55
66
"""
77

8-
from urllib.error import HTTPError
9-
8+
import httpx
109
from bs4 import BeautifulSoup
11-
from requests import exceptions, get
1210

13-
BASE_URL = "https://www.wellrx.com/prescriptions/{0}/{1}/?freshSearch=true"
11+
BASE_URL = "https://www.wellrx.com/prescriptions/{}/{}/?freshSearch=true"
1412

1513

1614
def fetch_pharmacy_and_price_list(drug_name: str, zip_code: str) -> list | None:
1715
"""[summary]
1816
1917
This function will take input of drug name and zipcode,
2018
then request to the BASE_URL site.
21-
Get the page data and scrape it to the generate the
22-
list of lowest prices for the prescription drug.
19+
Get the page data and scrape it to generate the
20+
list of the lowest prices for the prescription drug.
2321
2422
Args:
2523
drug_name (str): [Drug name]
@@ -28,12 +26,12 @@ def fetch_pharmacy_and_price_list(drug_name: str, zip_code: str) -> list | None:
2826
Returns:
2927
list: [List of pharmacy name and price]
3028
31-
>>> fetch_pharmacy_and_price_list(None, None)
32-
33-
>>> fetch_pharmacy_and_price_list(None, 30303)
34-
35-
>>> fetch_pharmacy_and_price_list("eliquis", None)
36-
29+
>>> print(fetch_pharmacy_and_price_list(None, None))
30+
None
31+
>>> print(fetch_pharmacy_and_price_list(None, 30303))
32+
None
33+
>>> print(fetch_pharmacy_and_price_list("eliquis", None))
34+
None
3735
"""
3836

3937
try:
@@ -42,25 +40,22 @@ def fetch_pharmacy_and_price_list(drug_name: str, zip_code: str) -> list | None:
4240
return None
4341

4442
request_url = BASE_URL.format(drug_name, zip_code)
45-
response = get(request_url, timeout=10)
46-
47-
# Is the response ok?
48-
response.raise_for_status()
43+
response = httpx.get(request_url, timeout=10).raise_for_status()
4944

5045
# Scrape the data using bs4
5146
soup = BeautifulSoup(response.text, "html.parser")
5247

5348
# This list will store the name and price.
5449
pharmacy_price_list = []
5550

56-
# Fetch all the grids that contains the items.
51+
# Fetch all the grids that contain the items.
5752
grid_list = soup.find_all("div", {"class": "grid-x pharmCard"})
5853
if grid_list and len(grid_list) > 0:
5954
for grid in grid_list:
6055
# Get the pharmacy price.
6156
pharmacy_name = grid.find("p", {"class": "list-title"}).text
6257

63-
# Get price of the drug.
58+
# Get the price of the drug.
6459
price = grid.find("span", {"p", "price price-large"}).text
6560

6661
pharmacy_price_list.append(
@@ -72,7 +67,7 @@ def fetch_pharmacy_and_price_list(drug_name: str, zip_code: str) -> list | None:
7267

7368
return pharmacy_price_list
7469

75-
except (HTTPError, exceptions.RequestException, ValueError):
70+
except (httpx.HTTPError, ValueError):
7671
return None
7772

7873

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy