-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
55 lines (46 loc) · 1.3 KB
/
database.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
import firebase_admin
import streamlit as st
from firebase_admin import credentials
from firebase_admin import db
@st.cache_data
def initialize_firebase_app():
cred = credentials.Certificate("serviceAccountKey.json")
firebase_admin.initialize_app(cred, {
'databaseURL': "#place your database URL here"
})
# Json Structure that we are going to send to the FireBase Real Time Database
# data = {
# 'Sadness/Heartbreak':
# [
# {
# 'song_name': "Some one like you",
# 'singer': "adele",
# },
# {
# 'song_name': "stay",
# 'singer': "Rihanna"
# }
# ],
# 'Love/Romance':
# [
# {
# 'song_name': "Thinking out loud",
# 'artist': "Ed sheeran"
# },
# {
# 'song_name': "Love story",
# 'artist': "taylor swift"
# }
# ]
#
# }
def add_data(emotion, songs, artists):
new_entry_ref = db.reference('Emotions').child(emotion).child('songs')
song_list = []
for song, artist in zip(songs, artists):
data = {
'song_name': song,
'artist': artist
}
song_list.append(data)
new_entry_ref.set(song_list)