-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload.py
28 lines (21 loc) · 835 Bytes
/
upload.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
import csv
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
# Initialize Firebase Admin SDK
cred = credentials.Certificate("admin.json") # Path to your service account key file
firebase_admin.initialize_app(cred)
# Initialize Firestore client
db = firestore.client()
def upload_data_to_firestore(csv_file_path, collection_name):
# Read data from CSV file
with open(csv_file_path, "r") as file:
reader = csv.DictReader(file)
data = list(reader)
# Upload data to Firestore
for row in data:
# Add data to Firestore collection
db.collection(collection_name).add(row)
print("Data uploaded:", row)
# Call the function with your CSV file path and Firestore collection name
upload_data_to_firestore("your_dataset.csv", "test_ml")