Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kl_task4_1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
arun.uday
kl_task4_1
Commits
8cc3e905
Commit
8cc3e905
authored
Feb 03, 2023
by
arun.uday
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v5
parent
e1eb9c50
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
97 additions
and
80 deletions
+97
-80
.idea/sonarlint/issuestore/index.pb
+3
-0
scripts/constants/file_constants.py
+0
-2
scripts/constants/proj_constants.py
+9
-0
scripts/core/database/postgres/postgres_connect.py
+4
-4
scripts/core/database/postgres/queries/post_queries.py
+16
-11
scripts/core/handlers/data_insert.py
+3
-3
scripts/core/handlers/delete_db_data.py
+2
-2
scripts/core/handlers/get_post_columns.py
+3
-2
scripts/core/handlers/mongo_db_operations.py
+7
-8
scripts/core/handlers/postgres_data_del.py
+22
-6
scripts/core/handlers/postgres_data_insert.py
+3
-5
scripts/core/handlers/postgres_data_update.py
+3
-4
scripts/core/handlers/postgres_data_view.py
+7
-16
scripts/core/handlers/postgres_db_operations.py
+8
-9
scripts/core/handlers/postgres_table_create.py
+2
-3
scripts/core/handlers/update_mongo_db.py
+2
-2
scripts/core/handlers/view_data_db.py
+3
-3
No files found.
.idea/sonarlint/issuestore/index.pb
View file @
8cc3e905
No preview for this file type
scripts/constants/file_constants.py
deleted
100644 → 0
View file @
e1eb9c50
# Exception constant
exception_msg
=
"Exception occurred"
scripts/constants/proj_constants.py
0 → 100644
View file @
8cc3e905
class
ConstantsValues
:
# Exception constant
exception_msg
=
"Exception occurred"
# column names
columns_names
=
[
'product_id'
,
'product_name'
,
'product_category'
,
'retail_price'
,
'discount_price'
,
'description'
,
'overall_rating'
]
scripts/core/database/postgres/postgres_connect.py
View file @
8cc3e905
...
...
@@ -2,8 +2,8 @@
import
psycopg2
as
py
from
scripts.config.postgres_connect_config
import
host_name
,
port
,
dbname
,
user
,
password
from
scripts.constants.
file_constants
import
exception_msg
from
scripts.constants.
proj_constants
import
ConstantsValues
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
try
:
postgres_client
=
py
.
connect
(
host
=
host_name
,
port
=
port
,
user
=
user
,
password
=
password
)
...
...
@@ -12,7 +12,7 @@ try:
# creating cursor for the postgres
cur
=
postgres_client
.
cursor
()
cur
.
execute
(
"SELECT datname FROM pg_database WHERE datistemplate = false;"
)
cur
.
execute
(
QueriesPost
()
.
databases
()
)
# Fetch the result
result
=
cur
.
fetchall
()
...
...
@@ -27,4 +27,4 @@ try:
postgres_client
.
commit
()
cur
.
execute
(
f
'CREATE DATABASE {dbname}'
)
except
Exception
as
e
:
print
(
f
'{exception_msg},{e}'
)
print
(
f
'{
ConstantsValues().
exception_msg},{e}'
)
scripts/core/database/postgres/queries/post_queries.py
View file @
8cc3e905
...
...
@@ -3,20 +3,25 @@ from scripts.config.postgres_connect_config import products
class
QueriesPost
:
@staticmethod
def
databases
():
db
=
"SELECT datname FROM pg_database WHERE datistemplate = false;"
return
db
@staticmethod
def
create_table
():
table
=
f
"CREATE TABLE if not exists {products} "
\
f
"(
Product_Id SERIAL PRIMARY KEY, Product_N
ame VARCHAR(255),"
\
f
"
Product_C
ategory VARCHAR(255),"
\
f
"
Retail_P
rice INT,"
\
f
"
Discounted_P
rice INT,"
\
f
"
D
escription VARCHAR(255),"
\
f
"
Overall_R
ating INT)"
f
"(
product_id SERIAL PRIMARY KEY, product_n
ame VARCHAR(255),"
\
f
"
product_c
ategory VARCHAR(255),"
\
f
"
retail_p
rice INT,"
\
f
"
discounted_p
rice INT,"
\
f
"
d
escription VARCHAR(255),"
\
f
"
overall_r
ating INT)"
return
table
@staticmethod
def
insert_data
():
insert_data
=
f
"INSERT INTO {products} (
Product_Name, Product_Category, Retail_Price, Discounted_P
rice,"
\
f
"
Description, Overall_R
ating) VALUES (
%
s,
%
s,
%
s,
%
s,
%
s,
%
s)"
insert_data
=
f
"INSERT INTO {products} (
product_name, product_category, retail_price, discounted_p
rice,"
\
f
"
description, overall_r
ating) VALUES (
%
s,
%
s,
%
s,
%
s,
%
s,
%
s)"
return
insert_data
@staticmethod
...
...
@@ -31,10 +36,10 @@ class QueriesPost:
@staticmethod
def
fetch_all
():
fetch_data
=
f
"SELECT * FROM {products}"
fetch_data
=
f
"SELECT * FROM {products}
ORDER BY product_id ASC
"
return
fetch_data
@staticmethod
def
delete_data
(
field_name
,
del_data
):
del_val
=
f
"DELETE FROM {products} WHERE {
field_name} = {
del_data}"
def
delete_data
(
del_data
):
del_val
=
f
"DELETE FROM {products} WHERE {del_data}"
return
del_val
scripts/core/handlers/data_insert.py
View file @
8cc3e905
...
...
@@ -9,7 +9,7 @@ def read_inputs():
retail_price
=
int
(
input
(
"Enter the retail price: "
))
discount_price
=
int
(
input
(
"Enter the discounted price: "
))
description
=
input
(
"Enter the product description: "
)
over_rating
=
in
put
(
"Enter the overall rating"
)
over_rating
=
in
t
(
input
(
"Enter the overall rating"
)
)
return
p_id
,
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
...
...
@@ -17,8 +17,8 @@ def read_inputs():
# inserting data to mongo
def
insert_data_db
(
db
,
p_id
,
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
):
try
:
insert_res
=
MongoDBQuery
()
.
insert
(
db
,
p_id
,
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
)
insert_res
=
MongoDBQuery
()
.
insert
(
db
,
p_id
,
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
)
return
insert_res
except
Exception
as
e
:
print
(
"Exception occurred :"
,
e
)
scripts/core/handlers/delete_db_data.py
View file @
8cc3e905
# deleting data
# getting user inputs
from
scripts.constants.proj_constants
import
ConstantsValues
from
scripts.core.database.mongo.queries.mongodb_queires
import
MongoDBQuery
def
delete_db_input
():
columns_
=
[
'product_id'
,
'product_name'
,
'product_category'
,
'retail_price'
,
'discount_price'
,
'description'
,
'overall_rating'
]
columns_
=
ConstantsValues
()
.
columns_names
integer_val
=
[
0
,
3
,
4
,
6
]
counter
=
0
condition_values
=
{}
...
...
scripts/core/handlers/get_post_columns.py
View file @
8cc3e905
from
scripts.config.postgres_connect_config
import
products
from
scripts.core.database.postgres.postgres_connect
import
cur
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
def
post_columns
():
# Execute a SELECT statement to get the column names of a table
cur
.
execute
(
f
"SELECT * FROM {products} LIMIT 0"
)
cur
.
execute
(
QueriesPost
()
.
fetch_all
()
)
# Get the column names
field_names
=
[
desc
[
0
]
for
desc
in
cur
.
description
]
...
...
scripts/core/handlers/mongo_db_operations.py
View file @
8cc3e905
# class for mongodb operations
from
scripts.constants.file_constants
import
exception_msg
from
scripts.config.postgres_connect_config
import
dbname
,
products
from
scripts.constants.proj_constants
import
ConstantsValues
from
scripts.core.database.mongo.mongodb_connect
import
client
from
scripts.core.handlers.data_insert
import
insert_data_db
,
read_inputs
from
scripts.core.handlers.delete_db_data
import
delete_db_input
,
db_delete
...
...
@@ -16,8 +17,8 @@ class MongoDbStart:
except
Exception
as
e
:
print
(
"Connection failed: "
,
e
)
else
:
db
=
client_con
[
'storeManager'
]
store_manager
=
db
[
'products'
]
db
=
client_con
[
dbname
]
store_manager
=
db
[
products
]
return
store_manager
# mongo data insert
...
...
@@ -49,7 +50,7 @@ class MongoDbStart:
else
:
print
(
"Data not updated"
)
except
Exception
as
e
:
print
(
f
'{exception_msg}{e}'
)
print
(
f
'{
ConstantsValues().
exception_msg}{e}'
)
# mongo delete data
@staticmethod
...
...
@@ -62,7 +63,7 @@ class MongoDbStart:
else
:
print
(
"Data not deleted"
)
except
Exception
as
e
:
print
(
f
'{exception_msg}{e}'
)
print
(
f
'{
ConstantsValues().
exception_msg}{e}'
)
# mongo view data
@staticmethod
...
...
@@ -72,6 +73,4 @@ class MongoDbStart:
view_fields
(
db
,
field_filter
)
except
Exception
as
e
:
print
(
f
'{exception_msg}{e}'
)
print
(
f
'{ConstantsValues().exception_msg}{e}'
)
scripts/core/handlers/postgres_data_del.py
View file @
8cc3e905
# deleting data
# getting user inputs
from
scripts.con
fig.postgres_connect_config
import
product
s
from
scripts.con
stants.proj_constants
import
ConstantsValue
s
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
# user input
def
delete_db_post
():
field_name
=
input
(
"Enter the field condition: "
)
del_data
=
int
(
input
(
"Enter the data: "
))
columns_
=
ConstantsValues
()
.
columns_names
integer_val
=
[
0
,
3
,
4
,
6
]
counter
=
0
condition_values
=
{}
print
(
"Conditions"
)
while
counter
<
len
(
columns_
):
field_value
=
input
(
f
"Enter the {columns_[counter]} data: "
)
if
field_value
!=
''
and
(
counter
in
integer_val
):
condition_values
.
update
({
f
'{columns_[counter]}'
:
int
(
field_value
)})
if
field_value
!=
''
and
(
counter
not
in
integer_val
):
condition_values
.
update
({
f
'{columns_[counter]}'
:
f
'{field_value}'
})
counter
+=
1
return
field_name
,
del_data
return
condition_values
# deleting the record
def
db_delete_post
(
cur
,
field_name
,
del_data
):
return
cur
.
execute
(
QueriesPost
()
.
delete_data
(
field_name
,
del_data
))
def
db_delete_post
(
cur
,
condition_values
):
conditions
=
[
f
"{field} = '{value}'"
for
field
,
value
in
condition_values
.
items
()]
conditions
=
"and "
.
join
(
conditions
)
if
conditions
:
cur
=
cur
.
execute
(
QueriesPost
()
.
delete_data
(
condition_values
))
else
:
cur
=
None
return
cur
scripts/core/handlers/postgres_data_insert.py
View file @
8cc3e905
# reading user inputs
from
scripts.config.postgres_connect_config
import
products
from
scripts.constants.file_constants
import
exception_msg
from
scripts.constants.proj_constants
import
ConstantsValues
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
# user inputs
def
read_inputs_post
():
p_id
=
int
(
input
(
"Enter the product id: "
))
p_name
=
input
(
"Enter the product name: "
)
p_category
=
input
(
"Enter the category: "
)
retail_price
=
int
(
input
(
"Enter the retail price: "
))
...
...
@@ -14,7 +12,7 @@ def read_inputs_post():
description
=
input
(
"Enter the product description: "
)
over_rating
=
input
(
"Enter the overall rating"
)
return
p_
id
,
p_
name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
return
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
# insert in to table
...
...
@@ -23,7 +21,7 @@ def insert_data_post(cur, p_name, p_category, retail_price, discount_price, desc
val_data
=
[
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
]
cur
.
execute
(
QueriesPost
()
.
insert_data
(),
val_data
)
except
Exception
as
e
:
print
(
f
'{exception_msg},{e}'
)
print
(
f
'{
ConstantsValues().
exception_msg},{e}'
)
return
False
else
:
return
True
scripts/core/handlers/postgres_data_update.py
View file @
8cc3e905
# updating the db
from
scripts.con
fig.postgres_connect_config
import
product
s
from
scripts.con
stants.proj_constants
import
ConstantsValue
s
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
from
scripts.core.handlers.get_post_columns
import
post_columns
# user data
def
input_update_post
():
columns_
=
post_columns
()
columns_
=
ConstantsValues
()
.
columns_names
counter
=
0
condition_values
=
{}
print
(
"Conditions"
)
...
...
@@ -35,7 +34,7 @@ def db_update_post(cur, condition_values, update_values):
updates
=
[
f
"{field} = '{value}'"
for
field
,
value
in
update_values
.
items
()]
updates
=
", "
.
join
(
updates
)
if
conditions
and
updates
:
cur
=
cur
.
execute
(
QueriesPost
()
.
update_data
())
cur
=
cur
.
execute
(
QueriesPost
()
.
update_data
(
updates
,
conditions
))
else
:
cur
=
None
return
cur
scripts/core/handlers/postgres_data_view.py
View file @
8cc3e905
...
...
@@ -2,7 +2,7 @@
# display conditions
import
pandas
as
pd
from
scripts.con
fig.postgres_connect_config
import
product
s
from
scripts.con
stants.proj_constants
import
ConstantsValue
s
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
from
scripts.core.handlers.get_post_columns
import
post_columns
...
...
@@ -27,17 +27,13 @@ def view_fields_post(cur, condition_values):
conditions
=
[
f
"{field} = '{value}'"
for
field
,
value
in
condition_values
.
items
()]
conditions
=
" and "
.
join
(
conditions
)
if
conditions
:
cur
.
execute
(
QueriesPost
()
.
fetch_conditions
())
print
(
conditions
)
cur
.
execute
(
QueriesPost
()
.
fetch_conditions
(
conditions
))
cursor_data
=
cur
.
fetchall
()
if
cursor_data
:
print
(
"Data collected...."
)
view_data
=
pd
.
DataFrame
((
view_data_record
for
view_data_record
in
cursor_data
),
columns
=
[
'Product Id'
,
'Product_Name'
,
'Product_Category'
,
'Retail_Price'
,
'Discounted_Price'
,
'Description'
,
'Overall_Rating'
])
view_data
=
pd
.
DataFrame
((
view_data_record
for
view_data_record
in
cursor_data
),
columns
=
ConstantsValues
()
.
columns_names
)
print
(
view_data
)
else
:
print
(
"Data fetching failed"
)
...
...
@@ -46,13 +42,8 @@ def view_fields_post(cur, condition_values):
cursor_data
=
cur
.
fetchall
()
if
cursor_data
:
print
(
"Data collected...."
)
view_data
=
pd
.
DataFrame
((
view_data_record
for
view_data_record
in
cursor_data
),
columns
=
[
'Product Id'
,
'Product_Name'
,
'Product_Category'
,
'Retail_Price'
,
'Discounted_Price'
,
'Description'
,
'Overall_Rating'
])
view_data
=
pd
.
DataFrame
((
view_data_record
for
view_data_record
in
cursor_data
),
columns
=
ConstantsValues
()
.
columns_names
)
print
(
view_data
)
else
:
print
(
"Data fetching failed"
)
scripts/core/handlers/postgres_db_operations.py
View file @
8cc3e905
# class for postgresSql
from
scripts.constants.
file_constants
import
exception_msg
from
scripts.constants.
proj_constants
import
ConstantsValues
from
scripts.core.database.postgres.postgres_connect
import
cur
,
postgres_client
from
scripts.core.handlers.postgres_data_del
import
delete_db_post
,
db_delete_post
from
scripts.core.handlers.postgres_data_insert
import
read_inputs_post
,
insert_data_post
...
...
@@ -19,14 +19,14 @@ class PostgresStart:
else
:
return
check_result
except
Exception
as
e
:
print
(
f
'{exception_msg}{e}'
)
print
(
f
'{
ConstantsValues().
exception_msg}{e}'
)
@staticmethod
def
post_insert
():
try
:
num_prod
=
int
(
input
(
"Enter the number of products: "
))
while
num_prod
>
0
:
p_
id
,
p_
name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
=
read_inputs_post
()
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
=
read_inputs_post
()
insert_check
=
insert_data_post
(
cur
,
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
)
if
insert_check
:
...
...
@@ -47,19 +47,19 @@ class PostgresStart:
else
:
print
(
"Data not updated"
)
except
Exception
as
e
:
print
(
f
'{exception_msg},{e}'
)
print
(
f
'{
ConstantsValues().
exception_msg},{e}'
)
@staticmethod
def
post_delete
():
try
:
field_name
,
del_data
=
delete_db_post
()
del_check
=
db_delete_post
(
cur
,
field_name
,
del_data
)
condition_values
=
delete_db_post
()
del_check
=
db_delete_post
(
cur
,
condition_values
)
if
del_check
is
None
:
print
(
"Data deleted"
)
else
:
print
(
"Data not deleted"
)
except
Exception
as
e
:
print
(
f
'{exception_msg}{e}'
)
print
(
f
'{
ConstantsValues().
exception_msg}{e}'
)
@staticmethod
def
post_view
():
...
...
@@ -68,11 +68,10 @@ class PostgresStart:
view_fields_post
(
cur
,
condition_values
)
except
Exception
as
e
:
print
(
f
'{exception_msg}{e}'
)
print
(
f
'{
ConstantsValues().
exception_msg}{e}'
)
@staticmethod
def
post_quit
():
# Close the cursor and connection
cur
.
close
()
postgres_client
.
close
()
scripts/core/handlers/postgres_table_create.py
View file @
8cc3e905
# creating a table
from
scripts.config.postgres_connect_config
import
products
from
scripts.constants.file_constants
import
exception_msg
from
scripts.constants.proj_constants
import
ConstantsValues
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
...
...
@@ -10,7 +9,7 @@ def create_table(cur):
cursor_db
=
cur
cursor_db
.
execute
(
QueriesPost
()
.
create_table
())
except
Exception
as
e
:
print
(
f
'{exception_msg},{e}'
)
print
(
f
'{
ConstantsValues().
exception_msg},{e}'
)
return
False
else
:
return
cursor_db
scripts/core/handlers/update_mongo_db.py
View file @
8cc3e905
# updating the db
from
scripts.constants.proj_constants
import
ConstantsValues
from
scripts.core.database.mongo.queries.mongodb_queires
import
MongoDBQuery
# user data
def
input_update_db
():
columns_
=
[
'product_id'
,
'product_name'
,
'product_category'
,
'retail_price'
,
'discount_price'
,
'description'
,
'overall_rating'
]
columns_
=
ConstantsValues
()
.
columns_names
integer_val
=
[
0
,
3
,
4
,
6
]
counter
=
0
condition_values
=
{}
...
...
scripts/core/handlers/view_data_db.py
View file @
8cc3e905
...
...
@@ -2,13 +2,13 @@
# display conditions
import
pandas
as
pd
from
scripts.constants.proj_constants
import
ConstantsValues
from
scripts.core.database.mongo.queries.mongodb_queires
import
MongoDBQuery
# display conditions
def
view_cond
():
columns_
=
[
'product_id'
,
'product_name'
,
'product_category'
,
'retail_price'
,
'discount_price'
,
'description'
,
'overall_rating'
]
columns_
=
ConstantsValues
()
.
columns_names
integer_val
=
[
0
,
3
,
4
,
6
]
counter
=
0
condition_values
=
{}
...
...
@@ -30,7 +30,7 @@ def view_fields(db, field_filter):
view_cursor_count
=
db
.
count_documents
(
field_filter
)
if
view_cursor_count
>
0
:
print
(
"Data collected...."
)
view_data
=
pd
.
json_normalize
(
(
view_data_record
for
view_data_record
in
view_data_cursor
)
)
view_data
=
pd
.
json_normalize
(
[
view_data_record
for
view_data_record
in
view_data_cursor
]
)
print
(
view_data
)
else
:
print
(
"Data fetching failed"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment