-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.py
137 lines (117 loc) · 4.13 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import pyrebase
import json
class DBhandler:
def __init__(self):
with open('./authentication/firebase_auth.json') as f:
config = json.load(f)
firebase = pyrebase.initialize_app(config)
self.db = firebase.database()
def insert_item(self, name, data, img_path):
item_info = {
"product_description": data['product_description'],
"product_place": data['product_place'],
"product_number": data['product_number'],
"product_category": data['product_category'],
"start_date": data['start_date'],
"end_date": data['end_date'],
"img_path": img_path
}
self.db.child("item").child(name).set(item_info)
print(data, img_path)
return True
def insert_user(self, data, password1):
user_info = {
"name": data['name'],
"email": data['email'],
"phone": data['phone'],
"id": data['id'],
"password": password1,
}
if self.user_duplicate_check(str(data['email'])) and password1!=data['password2']:
self.db.child("user").push(user_info)
print(data)
return True
else:
return False
def user_duplicate_check(self, email_string):
users = self.db.child("user").get()
print("users###",users.val())
if str(users.val()) == "None":
def get_items(self ):
items = self.db.child("item").get().val()
return items
def get_item_byname(self, name):
items = self.db.child("item").get()
target_value = ""
print("###########", name)
for res in items.each():
key_value = res.key()
if key_value == name:
target_value = res.val()
return target_value
def insert_user(self, data, pw):
user_info = {
"id": data['id'],
"pw": pw,
"name": data['name']
}
if self.user_duplicate_check(str(data['id'])):
self.db.child("user").push(user_info)
print(data)
return True
else:
return False
def user_duplicate_check(self, id_string):
users = self.db.child("user").get()
print("users###", users.val())
if str(users.val()) == "None": # first registration
return True
else:
for res in users.each():
value = res.val()
if value['email'] == email_string:
return False
return True
def insert_user2(self, data):
user_info = {
"nickname": data['nickname'],
"profile-img": data['profile-img']
}
self.db.child("user").push(user_info)
return True
if value['id'] == id_string:
return False
return True
def reg_review(self, data, img_path):
review_info ={
"name": data['name'],
"title": data['title'],
"rate": data['rate'],
"review": data['review'],
"img_path": img_path
}
self.db.child("review").child(data['name']).set(review_info)
return True
def get_heart_byname(self, uid, name):
hearts = self.db.child("heart").child(uid).get()
target_value=""
if hearts.val() == None:
return target_value
for res in hearts.each():
key_value = res.key()
if key_value == name:
target_value=res.val()
return target_value
def update_heart(self, user_id, isHeart, item):
heart_info ={
"interested": isHeart
}
self.db.child("heart").child(user_id).child(item).set(heart_info)
return True
def find_user(self, id_, pw_):
users = self.db.child("user").get()
target_value=[]
for res in users.each():
value = res.val()
if value['id'] == id_ and value['pw'] == pw_:
return True