Skip to content

Workshop 1 Homework: Blog Scraper + PostgreSQL + Docker - #143

Open
AshwiniUpadhyaya wants to merge 2 commits into
UniCourt:mainfrom
AshwiniUpadhyaya:main
Open

Workshop 1 Homework: Blog Scraper + PostgreSQL + Docker#143
AshwiniUpadhyaya wants to merge 2 commits into
UniCourt:mainfrom
AshwiniUpadhyaya:main

Conversation

@AshwiniUpadhyaya

Copy link
Copy Markdown

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.

Copilot AI lite review requested due to automatic review settings August 27, 2026 16:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread workshop1/app/scraper.py
Comment on lines +158 to +160
session.add(blog_post)
session.commit()
logger.info(f"Saved: {post_data['title']}")
Comment thread workshop1/app/database.py
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants