Spaces:
Sleeping
Sleeping
Delete database.py
Browse files- database.py +0 -43
database.py
DELETED
@@ -1,43 +0,0 @@
|
|
1 |
-
import pymysql
|
2 |
-
import json
|
3 |
-
import pandas as pd
|
4 |
-
import re
|
5 |
-
|
6 |
-
|
7 |
-
def initialize_database():
|
8 |
-
# Database Connection
|
9 |
-
db_params = {"host": "localhost",
|
10 |
-
"user": "cms-readonly-user",
|
11 |
-
"password": "%Reed!!",
|
12 |
-
"port": 3307,
|
13 |
-
"database": "veda_prod_v1"
|
14 |
-
}
|
15 |
-
db = pymysql.connect(**db_params)
|
16 |
-
return db
|
17 |
-
|
18 |
-
def execute_query(query):
|
19 |
-
db = initialize_database()
|
20 |
-
cursor = db.cursor()
|
21 |
-
try:
|
22 |
-
cursor.execute(query)
|
23 |
-
description = cursor.description
|
24 |
-
result = cursor.fetchall() # Fetch all rows from the result set
|
25 |
-
db.commit()
|
26 |
-
return description, result
|
27 |
-
except Exception as e:
|
28 |
-
print("Error executing query:", e)
|
29 |
-
db.rollback()
|
30 |
-
return None # Return None if an error occurs
|
31 |
-
finally:
|
32 |
-
db.close()
|
33 |
-
|
34 |
-
|
35 |
-
def _get_details_mantra_json(self, query):
|
36 |
-
description, data = execute_query(query)
|
37 |
-
df = pd.DataFrame(data)
|
38 |
-
df.columns = [x[0] for x in description]
|
39 |
-
mantra_json = df['mantra_json'].values[0]
|
40 |
-
cleaned_data = re.sub('<[^<]+?>', '', mantra_json)
|
41 |
-
return json.loads(cleaned_data)
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|