Add Homework 1Add homework 1 - #153
Open
pratham7187 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a simple web-scraping pipeline that fetches posts from the Python blog and stores results in a PostgreSQL database, packaged to run via Docker Compose for the workshop.
Changes:
- Added a
scraper.pyscript that scrapes blog posts and inserts them into Postgres (creating the table if needed). - Added Docker and Compose configuration to run Postgres + the scraper together.
- Updated Python dependencies and added a small DB connectivity test script.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
scraper.py |
Implements scraping + DB writes; introduces DB connection/config and insert behavior. |
test_db.py |
Adds a quick Postgres connection smoke test script. |
requirements.txt |
Switches dependency specification format (pinned → unpinned). |
Dockerfile |
Builds a container image to run the scraper. |
docker-compose.yml |
Defines the Postgres service and runs the scraper after DB healthcheck. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1
to
+11
| import requests | ||
| from bs4 import BeautifulSoup | ||
| import psycopg2 | ||
|
|
||
| conn = psycopg2.connect( | ||
| host="db", | ||
| database="blogdb", | ||
| user="postgres", | ||
| password="password", | ||
| port=5432 | ||
| ) |
Comment on lines
+26
to
+27
| response = requests.get(url) | ||
| soup = BeautifulSoup(response.text, "html.parser") |
Comment on lines
+33
to
+35
| for post in posts: | ||
| title = post.get_text(" ", strip=True) | ||
|
|
Comment on lines
+1
to
+9
| import psycopg2 | ||
|
|
||
| conn = psycopg2.connect( | ||
| host="localhost", | ||
| database="blogdb", | ||
| user="postgres", | ||
| password="password", | ||
| port=5432 | ||
| ) |
Comment on lines
+17
to
+22
| cursor.execute(""" | ||
| CREATE TABLE IF NOT EXISTS blogs ( | ||
| id SERIAL PRIMARY KEY, | ||
| title TEXT NOT NULL | ||
| ) | ||
| """) |
Comment on lines
+36
to
+39
| cursor.execute( | ||
| "INSERT INTO blogs (title) VALUES (%s)", | ||
| (title,) | ||
| ) |
Comment on lines
+4
to
+12
| environment: | ||
| POSTGRES_DB: blogdb | ||
| POSTGRES_USER: postgres | ||
| POSTGRES_PASSWORD: password | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U postgres -d blogdb"] | ||
| interval: 5s | ||
| timeout: 5s | ||
| retries: 10 |
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.
No description provided.