-
Notifications
You must be signed in to change notification settings - Fork 24
/
firestore.py
37 lines (33 loc) · 1.18 KB
/
firestore.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
import keys
import requests as http
import firebase_admin
from firebase_admin import auth, firestore, credentials
import time
def authenticate():
token = auth.create_custom_token(keys.user_id)
body = {
'returnSecureToken': True,
'token': token
}
token = http.post(f'https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key={keys.firebase_api_key}', data=body)
token = token.json()
return token['idToken']
def uploadToFirestore(data):
try:
cred = credentials.Certificate('serviceAccountKey.json')
firebase_admin.initialize_app(cred)
client = firestore.client()
for i, row in data.iterrows():
client.collection('stock_picks').add({
'symbol': row['symbol'],
'name': row['name'],
'roa': row['roa'],
'pe_ratio': row['pe_ratio'],
'roa_ranking': row['roa_ranking'],
'pe_ranking': row['pe_ranking'],
'overall_ranking': row['overall_ranking'],
'industry': row['industry'],
'created_at': time.time()
})
except Exception as ex:
print(ex)