Skip to content

Scrape Python Insider blog and store data in PostgreSQL using Docker - #96

Open
mskandashyambhat wants to merge 1 commit into
UniCourt:mainfrom
mskandashyambhat:main
Open

Scrape Python Insider blog and store data in PostgreSQL using Docker#96
mskandashyambhat wants to merge 1 commit into
UniCourt:mainfrom
mskandashyambhat:main

Conversation

@mskandashyambhat

Copy link
Copy Markdown

Changes Made

  • Added web scraping for Python Insider blog posts using BeautifulSoup.
  • Stored the scraped data in PostgreSQL.
  • Added database setup and data insertion logic.
  • Dockerized the application using Docker Compose.
  • Added the required configuration and dependencies.

Testing

  • Verified that the scraper runs successfully.
  • Verified that the scraped data is stored in PostgreSQL.
  • Verified the application using Docker Compose.

Copilot AI lite review requested due to automatic review settings August 13, 2026 17:03

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

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 thread scraper.py
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-]+/?$")
Comment thread scraper.py


def parse_listing_page(html):
soup = BeautifulSoup(html, "html.parser")
Comment thread docker-compose.yaml
Comment on lines +8 to +11
environment:
POSTGRES_USER: workshop_user
POSTGRES_PASSWORD: workshop_pass
POSTGRES_DB: workshop_db
Comment thread docker-compose.yaml
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U workshop_user -d workshop_db"]
Comment thread docker-compose.yaml
Comment on lines +36 to +38
DB_NAME: workshop_db
DB_USER: workshop_user
DB_PASSWORD: workshop_pass
Comment thread db.py
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 thread db.py
Comment on lines +13 to +15
def get_connection(retries=10, delay=3):
last_error = None
for attempt in range(1, retries + 1):
Comment thread db.py
published_date DATE,
summary TEXT,
tags TEXT[],
scraped_at TIMESTAMP DEFAULT NOW()
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