-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddingDataToDB.py
76 lines (73 loc) · 2.1 KB
/
AddingDataToDB.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
cred = credentials.Certificate("serviceAccountKey.json",)
firebase_admin.initialize_app(cred, {
'databaseURL' : "https://attendanceproject-b8993-default-rtdb.firebaseio.com/",
'storageBucket': "attendanceproject-b8993.appspot.com"
})
ref = db.reference("Students")
# Python dictionary
data = {
"TP011111":
{
"name" : "Lee Wen Han",
"major" : "CS(AI)",
"starting_year" : 2021,
"total_attendance" : 20,
"grades" : "A",
"year" : 2,
"last_attendance_taken" : "2024-01-26 16:10:30",
},
"TP012345":
{
"name" : "Foo Ming Kuang",
"major" : "CS(SE)",
"starting_year" : 2023,
"total_attendance" : 10,
"grades" : "A+",
"year" : 2,
"last_attendance_taken" : "2024-01-26 16:10:30",
},
"TP063338":{
"name": "Dalton Gan",
"major": "SE",
"starting_year": 2024,
"total_attendance": 4,
"standing": "A++",
"year": 2,
"last_attendance_time": "2024-01-02 12:06:02"
},
"TP068713":{
"name": "Suzanne Lai",
"major": "AI",
"starting_year": 2022,
"total_attendance": 10,
"standing": "A",
"year": 2,
"last_attendance_time": "2024-01-02 15:09:02"
},
"TP088888":{
"name": "Karina",
"major": "Slay",
"starting_year": 2024,
"total_attendance": 10,
"standing": "A+",
"year": 1,
"last_attendance_time": "2024-01-09 06:06:06"
},
"TP054321":{
"name": "Elon Musk",
"major": "Ruining Lives",
"starting_year": 1995,
"total_attendance": 10,
"standing": "A+",
"year": 29,
"last_attendance_time": "2024-01-08 13:10:30"
},
}
# This is how to "unzip a dictionary in Python"
# writing the dictionary details into the realtime database
for key, value in data.items():
# Storing the vaue in the dictionary "children" for the key in the ref you created ("Students")
ref.child(key).set(value)