-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB_handler.py
More file actions
74 lines (64 loc) · 2.08 KB
/
Copy pathDB_handler.py
File metadata and controls
74 lines (64 loc) · 2.08 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
import pyrebase
import json
import uuid
class DBmodule:
def __init__(self):
with open("./auth/firebaseAuth.json") as f:
config = json.load(f)
firebase = pyrebase.initialize_app(config)
self.db = firebase.database()
self.storage = firebase.storage()
def login(self, uid, pwd):
users = self.db.child("users").get().val()
try:
userinfo = users[uid]
if userinfo["pwd"] == pwd:
return True
else:
return False
except:
return False
def signin_verification(self, uid):
users = self.db.child("users").get().val()
for i in users:
if uid == i:
return False
return True
def signin(self, id, pwd):
information={
"pwd":pwd
}
if self.signin_verification(id):
self.db.child("users").child(id).set(information)
return True
else:
return False
def write_post(self, photoid, Dtext):
information ={
"photo":"static/img/{}.jpeg".format(photoid),
"text":Dtext,
"category" : None
}
self.db.child("posts").child(photoid).set(information)
def update_category(self, photoid, category):
self.db.child("posts").child(photoid).update({"category":category})
def get_category(self, category):
post_list =[]
users_post =self.db.child("posts").get().val()
try:
for post in users_post.items():
if post[1]["category"]==category:
print(post[0]) #post[0]가 photoid?
post_list.append(post[0])
return post_list
except:
return post_list
def get_detail(self, photoid):
posts =self.db.child("posts").get().val()
try:
for post in posts.items():
if post[0] == photoid:
print(post[0])
return(post[1])
except:
return None