Goal: upload .txt files to Firebase Cloud Firestore in a Python script.
Files:
2010_01_10_weights.txt
- input for the script that will be uploaded to Firebaseupload_file.py
- script that performs upload
Navigate to your working directory.
python3 -m venv env
sets up your virtual environmentpip3 install --upgrade pip
to make update pip versionpip install firebase-admin
to install Firebase credentials
Download .json
certificate from Firebase Project and put it in wd
db.collection('<collection id>').document('<document id>').set(data)
data
must be a python dict. Fill it exactly how you'd like your document to be structured.
python3 upload_file.py [filename]
[filename]
doesn't need extension, and will automatically add .txt
- While this method works well for uploading a single file, if you have collected a lot of data, it might make more sense to be able to upload multiple files at once. Could implement it with bash scripting or in the python script itself.
- Dynamically create the
data
dictionary to properly type all variables instead of changing it on case-by-case basis for script.