Skip to content

Commit ece8914

Browse files
authored
Merge branch 'master' into simple-recursion-examples
2 parents d08a47d + d1a9486 commit ece8914

File tree

7 files changed

+116
-31
lines changed

7 files changed

+116
-31
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ ARG VARIANT=3.13-bookworm
33
FROM mcr.microsoft.com/vscode/devcontainers/python:${VARIANT}
44
COPY requirements.txt /tmp/pip-tmp/
55
RUN python3 -m pip install --upgrade pip \
6-
&& python3 -m pip install --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
7-
&& pipx install pre-commit ruff \
8-
&& pre-commit install
6+
&& python3 -m pip install --no-cache-dir -r /tmp/pip-tmp/requirements.txt \
7+
&& pipx install pre-commit ruff

.devcontainer/README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
1-
https://code.visualstudio.com/docs/devcontainers/tutorial
1+
# Development Container
2+
3+
This is **Devcontainer** configuration to provide a consistent development environment for all contributors.
4+
5+
## Features
6+
7+
- [x] Pre-configured **Python environment**
8+
- [x] Automatic installation of **pre-commit hooks**
9+
- [x] **Ruff** linter ready to check your code
10+
- [x] **Oh My Zsh** with plugins:
11+
- `zsh-autosuggestions`
12+
- `zsh-syntax-highlighting`
13+
14+
## Usage
15+
16+
1. Install [**Docker** ](https://www.docker.com/get-started/) and [**Visual Studio Code**](https://code.visualstudio.com/)
17+
2. Install the **Remote - Containers** extension in VS Code
18+
19+
- Do `CTRL+P`, paste this command and press `Enter`
20+
21+
```shell
22+
ext install ms-vscode-remote.remote-containers
23+
```
24+
3. Open this repository in VS Code
25+
4. When prompted, click **"Reopen in Container"**
26+
5. Wait for the environment to build and initialize
27+
28+
After setup:
29+
30+
- `pre-commit` hooks are installed
31+
- `ruff` and other tools are available
32+
- The shell uses Zsh by default
33+
34+
## Tips
35+
36+
To manually run checks on all files:
37+
38+
```bash
39+
pre-commit run --all-files
40+
```
41+
42+
> For further information here's [Microsoft tutorial about devcontainers.](https://code.visualstudio.com/docs/devcontainers/tutorial)

.devcontainer/devcontainer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
// Update 'VARIANT' to pick a Python version: 3, 3.11, 3.10, 3.9, 3.8
88
// Append -bullseye or -buster to pin to an OS version.
99
// Use -bullseye variants on local on arm64/Apple Silicon.
10-
"VARIANT": "3.13-bookworm",
10+
"VARIANT": "3.13-bookworm"
1111
}
1212
},
1313

14+
"postCreateCommand": "zsh .devcontainer/post_install",
15+
1416
// Configure tool-specific properties.
1517
"customizations": {
1618
// Configure properties specific to VS Code.
@@ -20,7 +22,8 @@
2022
"python.defaultInterpreterPath": "/usr/local/bin/python",
2123
"python.linting.enabled": true,
2224
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
23-
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy"
25+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
26+
"terminal.integrated.defaultProfile.linux": "zsh"
2427
},
2528

2629
// Add the IDs of extensions you want installed when the container is created.

.devcontainer/post_install

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Begin post-installation steps..."
4+
5+
set -e
6+
7+
echo "Installing pre-commit hooks..."
8+
pre-commit install
9+
10+
echo "Installing Oh My Zsh plugins..."
11+
12+
# Install zsh-autosuggestions if not present
13+
if [ ! -d "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" ]; then
14+
echo "Cloning zsh-autosuggestions..."
15+
git clone https://github.com/zsh-users/zsh-autosuggestions \
16+
"${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions"
17+
fi
18+
19+
# Install zsh-syntax-highlighting if not present
20+
if [ ! -d "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting" ]; then
21+
echo "Cloning zsh-syntax-highlighting..."
22+
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \
23+
"${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting"
24+
fi
25+
26+
echo "Configuring plugins in ~/.zshrc..."
27+
sed -i '/^plugins=/c\plugins=(git zsh-autosuggestions zsh-syntax-highlighting)' ~/.zshrc
28+
29+
echo "Post-installation steps completed successfully. Enjoy!"

.github/workflows/devcontainer_ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Test DevContainer Build
2+
3+
on:
4+
push:
5+
paths:
6+
- ".devcontainer/**"
7+
pull_request:
8+
paths:
9+
- ".devcontainer/**"
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: devcontainers/[email protected]
17+
with:
18+
push: never
19+
runCmd: "true"

.pre-commit-config.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ repos:
1616
- id: auto-walrus
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.11.11
19+
rev: v0.12.3
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)