-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirebaseAdminRun.py
More file actions
33 lines (22 loc) · 892 Bytes
/
Copy pathFirebaseAdminRun.py
File metadata and controls
33 lines (22 loc) · 892 Bytes
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
# This file is responsible for uploading the data in the form of a JSON to the firebase
import json
from Firebase import *
# Connect to firebase
#connect()
# Load data
json_data = 'SmithAthletes.json'
with open(json_data) as f:
smithAthletes = json.load(f)
# Add credentials to make connection
cred = credentials.Certificate("smithathletes-d8741-firebase-adminsdk-snc4k-3e47fd0006.json")
firebase_admin.initialize_app(cred, {"databaseURL": "https://smithathletes-d8741-default-rtdb.firebaseio.com/"})
# Database
db = firestore.client()
collection_ref = db.collection('SmithAthletes')
# Iterate through the JSON data and update the documents in the collection
for item in smithAthletes:
# Use the 'id' as the document ID
unique_id = str(item['id'])
doc_ref = collection_ref.document(unique_id)
# Set the document with the rest of the data
doc_ref.set(item)