├── .gitignore ├── read_csv.py └── main.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.json 2 | __pycache__/ 3 | *.csv -------------------------------------------------------------------------------- /read_csv.py: -------------------------------------------------------------------------------- 1 | import csv 2 | 3 | def readcsv(): 4 | data = [] 5 | with open('hospitals.csv', 'r') as csv_file: 6 | csv_reader = csv.reader(csv_file) 7 | next(csv_reader) # Skip the header row 8 | 9 | for row in csv_reader: 10 | name = row[0] 11 | address = row[1] 12 | specialization = row[2].split(",") 13 | contact = row[3] 14 | 15 | data.append({ 16 | "name": name, 17 | "address": address, 18 | "specialization": specialization, 19 | "contact": contact, 20 | }) 21 | return data 22 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # write data from csv to firestore 2 | 3 | import firebase_admin 4 | from firebase_admin import credentials 5 | from firebase_admin import firestore 6 | 7 | from read_csv import readcsv 8 | 9 | # Path to the service account key JSON file 10 | cred = credentials.Certificate('serviceAccountKey.json') 11 | 12 | # Initialize the app with the service account key 13 | firebase_admin.initialize_app(cred) 14 | 15 | # Get a reference to the Firestore database 16 | db = firestore.client() 17 | 18 | # Create a reference to the hospitals collection 19 | hospitals_ref = db.collection('hospital_data') 20 | 21 | for hospital in readcsv(): 22 | hospitals_ref.document(hospital["name"]).set(hospital) --------------------------------------------------------------------------------