Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions homework1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.10.2-alpine3.15
# Create directories
RUN mkdir -p /root/workspace/src
COPY ./web_scraping_sample.py /root/workspace/src
# Switch to project directory
WORKDIR /root/workspace/src
# Install required packages
RUN pip install --upgrade pip
RUN pip install requests bs4 html5lib
26 changes: 26 additions & 0 deletions homework1/connect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import psycopg2
import csv
conn = psycopg2.connect(
host="172.17.0.2",
port="5432",
dbname="demodb",
user="postgres",
password="123456"
)

cur = conn.cursor()

with open('output2.csv','r') as f:
csv_reader = csv.reader(f)
next(csv_reader)
for row in csv_reader:
if row[1] =="":
row[1] = "N/A"

cur.execute("INSERT INTO demotable (column1, column2, column3) VALUES (%s, %s, %s)",(row[0], row[1],row[2]))

conn.commit()

cur.close()
conn.close()

10 changes: 10 additions & 0 deletions homework1/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
psql-db:
image: 'postgres:14'
container_name: psql-db1
environment:
- PGPASSWORD=123456
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=123456
ports:
- '5434:5432'

10 changes: 10 additions & 0 deletions homework1/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.10.2-alpine3.15
# Create directories
RUN mkdir -p /root/workspace/src
COPY ./web_scraping_sample.py /root/workspace/src
# Switch to project directory
WORKDIR /root/workspace/src
# Install required packages
RUN pip install --upgrade pip
RUN pip install requests bs4 html5lib

43 changes: 43 additions & 0 deletions homework1/output2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
column1,column2,column3
count,count1,"
Python 3.11.3, Python 3.10.11 and 3.12.0 alpha 7 are available
"
count,count2,Python 3.12.0 alpha 7
count,count3,Python 3.11.3
count,count4,Python 3.10.11
count,count5,We hope you enjoy the new releases!
count,count6,"
Python 3.12.0 alpha 6 released
"
count,count7,"
Python 3.11.2, Python 3.10.10 and 3.12.0 alpha 5 are available
"
count,count8,Python 3.12.0 alpha 5
count,count9,Python 3.11.2
count,count10,Python 3.10.10
count,count11,"Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation.https://www.python.org/psf/ Your friendly release team,Ned Deily @nadSteve Dower @steve.dowerPablo Galindo Salgado @pablogsalŁukasz Langa @ambvThomas Wouters @thomas"
count,count12,"
Python 3.12.0 alpha 4 released
"
count,count13,"
Python 3.11.1, 3.10.9, 3.9.16, 3.8.16, 3.7.16, and 3.12.0 alpha 3 are now available
"
count,count14,"
Python 3.12.0 alpha 3"
count,count15,"
Python 3.11.1"
count,count16,"
Python 3.10.9"
count,count17,"
Python 3.9.16"
count,count18,"
Python 3.8.16"
count,count19,"
Python 3.7.16"
count,count20,"
Python 3.12.0 alpha 2 released
"
count,count21,"
Python 3.12.0 alpha 1 released
"
count,count22,And now for something completely different
22 changes: 22 additions & 0 deletions homework1/web_scraping_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import requests
import csv
from bs4 import BeautifulSoup
res=requests.get("https://blog.python.org/")
soup = BeautifulSoup(res.content, "html.parser")
titles = soup.find_all("h3")
titles_list=[]
count=1
for title in titles:
d={}
d['column1']=f'count'
d['column2']=f'count{count}'
d['column3']=title.text
count+=1
titles_list.append(d)
filename='output2.csv'
with open(filename,'w',newline='') as f:
writer = csv.DictWriter(f,['column1','column2', 'column3'])
writer.writeheader()
writer.writerows(titles_list)
f.close()