-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbHandler.py
87 lines (74 loc) · 2.45 KB
/
dbHandler.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
# Fetch the service account key JSON file contents
cred = credentials.Certificate('crime-preventor-firebase-adminsdk-lhutu-846b4f6f8d.json')
# Initialize the app with a service account, granting admin privileges
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://crime-preventor-default-rtdb.firebaseio.com/'
})
ref = db.reference('Criminal')
def insertData(data):
result = ref.push({
'Name':data["Name"],
'Father Name':data["Father's Name"],
'Mother Name':data["Mother's Name"],
'Gender': data["Gender"],
'DOB':data["DOB(yyyy-mm-dd)"],
'Blood Group':data["Blood Group"],
'Identification Mark':data["Identification Mark"],
'Nationality':data["Nationality"],
'Religion':data["Religion"],
'Crime done':data["Crimes Done"]
})
return(result)
# def retrieveData(name):
# id = None
# crim_data = None
# db = pymysql.connect("localhost", "criminaluser", "", "criminaldb")
# cursor = db.cursor()
# print("database connected")
# query = "SELECT * FROM criminaldata WHERE name='%s'"%name
# try:
# cursor.execute(query)
# result = cursor.fetchone()
# id=result[0]
# crim_data = {
# "Name" : result[1],
# "Father's Name" : result[2],
# "Mother's Name" : result[3],
# "Gender" : result[4],
# "DOB(yyyy-mm-dd)" : result[5],
# "Blood Group" : result[6],
# "Identification Mark" : result[7],
# "Nationality" : result[8],
# "Religion" : result[9],
# "Crimes Done" : result[10]
# }
# print("data retrieved")
# except:
# print("Error: Unable to fetch data")
# db.close()
# print("connection closed")
# return (id, crim_data)
def retrieveData(name):
ide = None
crim_data = None
#print(name)
snapshot = ref.order_by_child('Name').equal_to(name).get()
temp= list(snapshot.items())
crim_data = temp[0][1]
ide = temp[0][0]
return(ide,crim_data)
def retrieveMissingPeopleData(name):
refPoliceStationData = db.reference('Police Station/123456')
ide = None
crim_data = None
snapshot = refPoliceStationData.get()
temp= snapshot
print("list ",temp)
data = temp
ide = name
print("crim_data ",crim_data)
#print(name)
return(ide,data)