-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase.py
More file actions
142 lines (117 loc) · 4.09 KB
/
Copy pathdatabase.py
File metadata and controls
142 lines (117 loc) · 4.09 KB
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
138
139
140
141
142
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 ={
"seller": data['seller'],
"addr": data['addr'],
"email": data['email'],
"category": data['category'],
"card": data['card'],
"status": data['status'],
"phone": data['phone'],
"img_path": img_path
}
self.db.child("item").child(name).set(item_info)
print(data,img_path)
return True
def insert_user(self, data, pw):
user_info ={
"id": data['id'],
"pw": pw,
"nickname": data['nickname']
}
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['id'] == id_string:
return False
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
return False
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 reg_review(self, data, img_path):
review_info ={
"title": data['title'],
"rate": data['reviewStar'],
"review": data['reviewContents'],
"img_path": img_path
}
self.db.child("review").child(data['name']).set(review_info)
return True
def get_reviews(self):
reviews = self.db.child("review").get().val()
return reviews
def get_review_byname(self, name):
restaurants = self.db.child("review").get()
target_value=""
print("###########",name)
for res in restaurants.each():
key_value = res.key()
if key_value == name:
target_value=res.val()
return target_value
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 get_items_bycategory(self, cate):
items = self.db.child("item").get()
target_value=[]
target_key=[]
for res in items.each():
value = res.val()
key_value = res.key()
if value['category'] == cate:
target_value.append(value)
target_key.append(key_value)
print("######target_value",target_value)
new_dict={}
for k,v in zip(target_key,target_value):
new_dict[k]=v
return new_dict