forked from AJAYK-01/KTU-Notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
44 lines (35 loc) · 1.28 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
from firebase import Firebase
from decouple import config
config = {
"apiKey": config('APIKEY'),
"authDomain": config('AUTHDOMAIN'),
"databaseURL": config('DATABASEURL'),
"projectId": config('PROJECTID'),
"storageBucket": config('STORAGEBUCKET')
}
firebase = Firebase(config)
db = firebase.database()
def getData():
""" Returns the scraped notifications from the Firebase Database as dictionary """
data = []
notifs = db.child("notifs").get().val()
for notif in notifs:
data.append(notif)
return data
def setData(data):
""" Updates the notifications Firebase DB with the new notifications """
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")