-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdatabase.py
47 lines (41 loc) · 1.27 KB
/
database.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
import numpy as np
import pickle
import os
class Database:
def write(self,name,cnic,*args):
if os.path.isfile('./db.pkl'):
with open('./db.pkl', 'rb') as book:
data = pickle.load(book)
print(data)
irises = []
for i in args:
irises.append(i.ravel())
username = name.replace(" ","")
if username not in data.keys():
data[username] = {
'name':name,
'cnic':cnic,
'iris':irises,
'customers':{}
}
print(data)
with open('./db.pkl','wb') as book:
pickle.dump(data, book)
else:
data = {}
irises = []
for i in args:
irises.append(i.ravel())
username = name.replace(" ","")
data[username] = {
'name':name,
'cnic':cnic,
'iris':irises,
'customers':{}
}
with open('./db.pkl','wb') as book:
pickle.dump(data,book)
def read(self):
with open('./db.pkl','rb') as book:
data = pickle.load(book)
return data