Scrape Python Insider blog and store data in PostgreSQL using Docker - #96
Open
mskandashyambhat wants to merge 1 commit into
Open
Scrape Python Insider blog and store data in PostgreSQL using Docker#96mskandashyambhat wants to merge 1 commit into
mskandashyambhat wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces the previous demo scraper with a Python Insider (blog.python.org) scraper that collects post metadata and persists it into PostgreSQL, packaged to run via Docker Compose for the workshop environment.
Changes:
- Added a new scraper (
scraper.py) and entrypoint (main.py) to fetch and parse Python Insider listing pages. - Added PostgreSQL persistence layer (
db.py) and a Compose setup to run the scraper against a Postgres container. - Updated containerization and dependencies (Dockerfile, docker-compose, requirements).
Reviewed changes
Copilot reviewed 6 out of 10 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
web_scraping_sample.py |
Removes the old sample scraper script. |
scraper.py |
Implements Python Insider listing-page scraping and post metadata extraction. |
db.py |
Adds Postgres connection/retry logic, table creation, and upsert inserts for posts. |
main.py |
Orchestrates scraping and DB persistence; supports MAX_PAGES for limiting scope. |
requirements.txt |
Updates Python dependencies for scraping and Postgres connectivity. |
Dockerfile |
Builds a runnable container image for the scraper app. |
docker-compose.yaml |
Adds a Postgres service and wires app container environment/healthchecks. |
Suppressed comments (1)
scraper.py:111
- requirements.txt includes lxml, but this BeautifulSoup call still uses "html.parser". Switching to "lxml" keeps behavior consistent and avoids carrying an unused dependency.
soup = BeautifulSoup(html, "html.parser")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+11
to
+12
| # Matches post links like /2026/08/python-31214-31116-31021 | ||
| POST_LINK_RE = re.compile(r"^/\d{4}/\d{2}/[\w-]+/?$") |
|
|
||
|
|
||
| def parse_listing_page(html): | ||
| soup = BeautifulSoup(html, "html.parser") |
Comment on lines
+8
to
+11
| environment: | ||
| POSTGRES_USER: workshop_user | ||
| POSTGRES_PASSWORD: workshop_pass | ||
| POSTGRES_DB: workshop_db |
| volumes: | ||
| - pgdata:/var/lib/postgresql/data | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U workshop_user -d workshop_db"] |
Comment on lines
+36
to
+38
| DB_NAME: workshop_db | ||
| DB_USER: workshop_user | ||
| DB_PASSWORD: workshop_pass |
Comment on lines
+6
to
+10
| DB_HOST = os.getenv("DB_HOST", "localhost") | ||
| DB_PORT = os.getenv("DB_PORT", "5432") | ||
| DB_NAME = os.getenv("DB_NAME", "workshop_db") | ||
| DB_USER = os.getenv("DB_USER", "workshop_user") | ||
| DB_PASSWORD = os.getenv("DB_PASSWORD", "workshop_pass") |
Comment on lines
+13
to
+15
| def get_connection(retries=10, delay=3): | ||
| last_error = None | ||
| for attempt in range(1, retries + 1): |
| published_date DATE, | ||
| summary TEXT, | ||
| tags TEXT[], | ||
| scraped_at TIMESTAMP DEFAULT NOW() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes Made
Testing