32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
|
|
# datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S")
|
|
import firebase_admin
|
|
from firebase_admin import credentials, firestore
|
|
import os
|
|
from google.cloud.firestore_v1.base_query import FieldFilter
|
|
from datetime import datetime
|
|
|
|
key_path = os.getcwd() + '/keys/hpos-qa-firebase-adminsdk.json'
|
|
cred = credentials.Certificate(key_path)
|
|
firebase_admin.initialize_app(cred)
|
|
def update_coefficent(source_collection):
|
|
db = firestore.client()
|
|
|
|
docs = db.collection(source_collection).where(filter = FieldFilter("deviceId", "==", "HCV-000-3001")).stream()
|
|
|
|
for doc in docs:
|
|
doc_id = doc.id #doc.to_dict()["_id"]
|
|
print(doc_id)
|
|
|
|
try:
|
|
db.collection(source_collection).document(doc_id).update({
|
|
"coefficients": [1, 0],
|
|
"calibratedAt": datetime.today().strftime("%Y-%m-%d %H:%M:%S")
|
|
})
|
|
print(f"Document with ID '{doc_id}' updated")
|
|
except Exception as e:
|
|
print(f"Error updating document with ID '{doc_id}' from the source collection: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
update_coefficent("devices")
|