-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpushToFirestore.py
More file actions
53 lines (43 loc) · 1.21 KB
/
pushToFirestore.py
File metadata and controls
53 lines (43 loc) · 1.21 KB
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
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import pandas as pd
from datetime import datetime
# initializations firebase
cred = credentials.Certificate('firebase-sdk.json')
firebase_admin.initialize_app(cred)
db = firestore.client()
doc_ref = db.collection('testusers')
# import data
df = pd.read_excel("data.xlsx")
# get uids from firebase using extractuid script
uiddict={}
# replace nan with empty string
df.fillna('', inplace=True)
# iterate through excel
print(df.shape[0] ,"rows in sheet")
c=0
k=df.keys()
for index, row in df.iterrows():
d={}
for j in k:
d[j]=row[j]
# done for firebase timestamp
try:
d["dateOfBirth"]=datetime.strptime(d["dateOfBirth"], '%d-%m-%Y')
except:
pass
try:
d["phoneNumber"]=str(int(d["phoneNumber"]))
except:
pass
try:
if (" +91"+d["phoneNumber"]+" " in uiddict):
d["uid"]=uiddict[" +91"+str(int(d["phoneNumber"]))+" "].replace(" ","")
doc_ref.document(d["uid"]).set(d)
c+=1
if c==5:
break
except:
pass
print(c,"rows pushed")