Last active
May 10, 2020 16:47
-
-
Save vishalroygeek/53e0732db538d1e81c1f6f993b8f542d to your computer and use it in GitHub Desktop.
A python script to get all the user data from firestore database and put it into a CSV file π
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import firebase_admin | |
from firebase_admin import credentials | |
from firebase_admin import firestore | |
import csv | |
#Initializing firebase | |
cred = credentials.Certificate("path/to/serviceAccount.json") | |
firebase_admin.initialize_app(cred) | |
db = firestore.client() | |
#Getting all the users from database | |
users = db.collection(u'users').stream() | |
#Opening a CSV file for users data | |
with open('path/to/users.csv', 'w', newline='') as file: | |
writer = csv.writer(file) | |
#Writing header row of CSV file. Change it according to your needs ;) | |
writer.writerow(["Name", "Email"]) | |
#Writing all the users data | |
for user in users: | |
writer.writerow([user.get("name"), user.get("email")]) | |
print("All users have been exported to the CSV file π") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment