-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysqldb_operations.py
63 lines (49 loc) · 1.49 KB
/
mysqldb_operations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import mysql.connector
import streamlit as st
import pandas as pd
# CREATE TABLE users(
# id VARCHAR(255) NOT NULL PRIMARY KEY,
# create_time DATETIME COMMENT 'Create Time',
# name VARCHAR(255),
# father_name VARCHAR(255),
# dob DATETIME,
# id_type VARCHAR(255) NOT NULL,
# embedding BLOB
# )
# Establish a connection to MySQL Server
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="toor",
database="ekyc"
)
mycursor=mydb.cursor()
print("Connection Established")
def insert_records(text_info):
sql = "INSERT INTO person_details(id, name, father_name, dob, id_type, embedding) VALUES (%s, %s, %s, %s, %s, %s)"
value = (text_info['ID'],
text_info['Name'],
text_info["Father's Name"],
text_info['DOB'], # Make sure this is formatted as a string 'YYYY-MM-DD'
text_info['ID Type'],
str(text_info['Embedding']))
mycursor.execute(sql, value)
mydb.commit()
def fetch_records(text_info):
sql = "SELECT * FROM person_details WHERE id =%s"
value = (text_info['ID'],)
mycursor.execute(sql, value)
result = mycursor.fetchall()
if result:
df = pd.DataFrame(result, columns=[desc[0] for desc in mycursor.description])
return df
else:
return pd.DataFrame()
def check_duplicacy(text_info):
is_duplicate = False
df = fetch_records(text_info)
if df.shape[0]>0:
is_duplicate = True
return is_duplicate
def get_data():
pass