-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase_connecting.py
54 lines (35 loc) · 1.4 KB
/
firebase_connecting.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
import firebase_admin
from firebase_admin import db
from datetime import datetime
# firebase connecting
def firebase_connectings(key):
print("databse started")
if not firebase_admin._apps:
cred_obj = firebase_admin.credentials.Certificate('attendance-34c91-firebase-adminsdk-n1vj8-18f67ea82c.json')
default_app = firebase_admin.initialize_app(cred_obj,{
'databaseURL': 'https://attendance-34c91-default-rtdb.firebaseio.com/'
})
# the root of the database
ref = db.reference("/")
#To get the data using keys
f = ref.child(str(key)).get()
# To get the current data
date = str(datetime.now().strftime("%d-%m-%Y"))
attendanceList =[]
for i in f['Attendance']:
attendanceList.append(i['Date'])
print(attendanceList)
if(str(date) not in attendanceList):
#append the status to the existing data
f['Attendance'].append({'AttendanceStatus': 'p', 'Date': date})
print(f)
#After appending to update the database
ref.child(str(key)).update(f)
print(key,"key is successfully update data in database")
else:
print(key ," The key is already in database")
# open the json data and set
#with open("data.json", "r") as f:
# file_contents = json.load(f)
# update the data in realtime database --> update , child , remove , get
#ref.set(file_contents)