Workshop 1 Homework: Blog Scraper + PostgreSQL + Docker - #143
Open
AshwiniUpadhyaya wants to merge 2 commits into
Open
Workshop 1 Homework: Blog Scraper + PostgreSQL + Docker#143AshwiniUpadhyaya wants to merge 2 commits into
AshwiniUpadhyaya wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a self-contained “Workshop 1” scraping pipeline that collects posts from blog.python.org, persists them to PostgreSQL via SQLAlchemy, and runs the stack via Docker Compose.
Changes:
- Introduces a BeautifulSoup-based scraper that paginates listing pages, visits each post, and writes results to Postgres.
- Adds SQLAlchemy database model + session/engine setup driven by environment variables.
- Adds Dockerfile, docker-compose stack, requirements, and an example env file to run locally/in containers.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
workshop1/env.example |
Provides example Postgres environment variables for local configuration. |
workshop1/Dockerfile |
Containerizes the scraper app and installs Python dependencies. |
workshop1/docker-compose.yaml |
Defines Postgres + scraper services and wires connectivity via env vars + healthcheck. |
workshop1/app/scraper.py |
Implements scraping, parsing, and persistence logic for blog posts. |
workshop1/app/requirements.txt |
Pins runtime dependencies (requests/bs4/SQLAlchemy/psycopg2). |
workshop1/app/database.py |
Defines the SQLAlchemy model and Postgres connection/session utilities. |
Suppressed comments (1)
workshop1/app/scraper.py:195
- If processing a post fails after a SQLAlchemy error (e.g., during insert/commit), the Session will be left in a failed transaction state and subsequent DB operations will keep failing until a rollback occurs. Rolling back in this exception handler keeps the scraper resilient and allows it to continue processing later posts.
except Exception as e:
logger.error(f"Failed to process {post['url']}: {e}")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+158
to
+160
| session.add(blog_post) | ||
| session.commit() | ||
| logger.info(f"Saved: {post_data['title']}") |
Comment on lines
+14
to
+17
| from sqlalchemy import create_engine, Column, Integer, String, Text, DateTime | ||
| from sqlalchemy.ext.declarative import declarative_base | ||
| from sqlalchemy.orm import sessionmaker | ||
| from datetime import datetime |
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.
Scrapes blog posts from blog.python.org using requests + BeautifulSoup, stores them in PostgreSQL via SQLAlchemy, and runs the whole pipeline in Docker containers using docker compose. Verified locally and successfully scraped and saved 16 posts.