Complete workshop 1 web scraping and PostgreSQL - #151
Open
darshanbaja wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the Workshop 1 scraper to collect structured post metadata from the Python Blog and persist results into a PostgreSQL database, with Docker configuration updates to run the scraper alongside Postgres.
Changes:
- Replaced the sample scraping logic with a Python Blog scraper that extracts title, URL, author, and publish date.
- Added PostgreSQL integration via
psycopg2with a duplicate-URL check before inserts. - Updated Docker/Docker Compose to install Python dependencies from
requirements.txtand add a Postgres service.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| web_scraping_sample.py | Scrapes Python Blog posts and writes results into PostgreSQL. |
| Dockerfile | Switches dependency installation to use requirements.txt. |
| docker-compose.yaml | Adds a Postgres service to run alongside the Python container. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+6
to
+10
| conn = psycopg2.connect( | ||
| host="psql-db", | ||
| database="workshop", | ||
| user="postgres", | ||
| password="postgres" |
| cursor = conn.cursor() | ||
|
|
||
| url = "https://blog.python.org/" | ||
| response = requests.get(url) |
Comment on lines
+36
to
+50
| cursor.execute( | ||
| "SELECT id FROM blogs WHERE url = %s", | ||
| (link,) | ||
| ) | ||
|
|
||
| existing_blog = cursor.fetchone() | ||
|
|
||
| if existing_blog is None: | ||
| cursor.execute( | ||
| """ | ||
| INSERT INTO blogs (title, url, author, published_date) | ||
| VALUES (%s, %s, %s, %s) | ||
| """, | ||
| (title, link, author, date) | ||
| ) |
Comment on lines
+5
to
+7
| COPY ./web_scraping_sample.py /root/workspace/src | ||
| COPY requirements.txt . | ||
|
|
|
|
||
| psql-db: | ||
| image: postgres:14 | ||
| container_name: workshop_postgres |
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.
I completed the Workshop 1 homework by updating the Python web scraping script to scrape blog titles, URLs, authors, and publication dates from the Python Blog. I also added PostgreSQL support to store the scraped data and updated the Docker configuration to run the Python scraper and PostgreSQL together. Duplicate blog URLs are checked before inserting new records.