-
Notifications
You must be signed in to change notification settings - Fork 7
/
db.py
49 lines (34 loc) · 1.17 KB
/
db.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
from firebase import Firebase
# from decouple import config
import os
config = {
"apiKey": os.environ['APIKEY'],
"authDomain": os.environ['AUTHDOMAIN'],
"databaseURL": os.environ['DATABASEURL'],
"projectId": os.environ['PROJECTID'],
"storageBucket": os.environ['STORAGEBUCKET']
}
firebase = Firebase(config)
db = firebase.database()
def getData():
data = []
notifs = db.child("notifs").get().val()
for notif in notifs:
data.append(notif)
return data
def setData(data):
db.child("notifs").set(data)
def users():
""" Gathers the list of Users from the Firebase Database as a dictionary"""
users = []
users = db.child("subs").get()
return dict(users.val())
def subscribe(chat_id):
""" Adds the user as a Subscriber in the Firebase Database """
db.child("subs").child(str(chat_id)).set("T")
def relevantsub(chat_id):
""" Adds the user as subscriber of Relevant notifications in the Firebase Database """
db.child("subs").child(str(chat_id)).set("R")
def unsubscribe(chat_id):
""" Sets the Subscription status of user to False in the Firebase Database """
db.child("subs").child(str(chat_id)).set("F")