From bd2f4536859285109b4140fd90ac51795baa620c Mon Sep 17 00:00:00 2001
From: Yashaswi315 <125741861+Yashaswi315@users.noreply.github.com>
Date: Tue, 25 Apr 2023 08:38:53 +0530
Subject: [PATCH] Add files via upload
---
yash/1.py | 25 +++++++++++++++++++++++++
yash/3.py | 12 ++++++++++++
yash/Dockerfile | 9 +++++++++
yash/docker-compose.yml | 9 +++++++++
yash/output2.csv | 14 ++++++++++++++
5 files changed, 69 insertions(+)
create mode 100644 yash/1.py
create mode 100644 yash/3.py
create mode 100644 yash/Dockerfile
create mode 100644 yash/docker-compose.yml
create mode 100644 yash/output2.csv
diff --git a/yash/1.py b/yash/1.py
new file mode 100644
index 0000000..35fd962
--- /dev/null
+++ b/yash/1.py
@@ -0,0 +1,25 @@
+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()
diff --git a/yash/3.py b/yash/3.py
new file mode 100644
index 0000000..06b1147
--- /dev/null
+++ b/yash/3.py
@@ -0,0 +1,12 @@
+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("h1")
+with open('output2.csv','w',newline='') as f:
+ writer = csv.writer(f)
+ writer.writerow(['column 1','column 2','column 3'])
+ for row in titles:
+ writer.writerow(row)
+f.close()
diff --git a/yash/Dockerfile b/yash/Dockerfile
new file mode 100644
index 0000000..5d757f1
--- /dev/null
+++ b/yash/Dockerfile
@@ -0,0 +1,9 @@
+FROM python:3.10.2-alpine3.15
+# Create directories
+RUN mkdir -p /root/workspace/src
+COPY ./hw.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
diff --git a/yash/docker-compose.yml b/yash/docker-compose.yml
new file mode 100644
index 0000000..15f0a8d
--- /dev/null
+++ b/yash/docker-compose.yml
@@ -0,0 +1,9 @@
+psql-db:
+ image: 'postgres:14'
+ container_name: psql-db1
+ environment:
+ - PGPASSWORD=123456
+ - POSTGRES_USER=postgres
+ - POSTGRES_PASSWORD=123456
+ ports:
+ - '5434:5432'
diff --git a/yash/output2.csv b/yash/output2.csv
new file mode 100644
index 0000000..cad69b5
--- /dev/null
+++ b/yash/output2.csv
@@ -0,0 +1,14 @@
+column 1,column 2,column 3
+"Major new features of the 3.12 series, compared to 3.11","More resources
+
+And now for something completely different
+
+Enjoy the new releases
+Major new features of the 3.12 series, compared to 3.11
+More resources
+",
+More resources,,And now for something completely different
+
,,
+And now for something completely different,,Enjoy the new releases
+Enjoy the new releases,,"Major new features of the 3.12 series, compared to 3.11"
+"Major new features of the 3.12 series, compared to 3.11",,"More resources"