clear current day users
This commit is contained in:
@@ -2,6 +2,7 @@ import functions_framework
|
||||
from google.cloud.firestore_v1.base_query import FieldFilter
|
||||
from firebase_admin import initialize_app, credentials, firestore
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
initialize_app()
|
||||
|
||||
@@ -34,7 +35,7 @@ def clear_users(request):
|
||||
source_collection = "patientData"
|
||||
|
||||
# Get all documents from the source collection
|
||||
source_docs = db.collection(source_collection).where(filter=FieldFilter("testStatus", "==", False)).stream()
|
||||
source_docs = db.collection(source_collection).where(filter=FieldFilter("createdAt", ">=", datetime.today().strftime("%Y-%m-%d"))).stream()
|
||||
count = 0
|
||||
for doc in source_docs:
|
||||
# Extract the document ID
|
||||
@@ -45,7 +46,8 @@ def clear_users(request):
|
||||
doc_data = doc.to_dict()
|
||||
|
||||
try:
|
||||
db.collection(source_collection).document(doc_id).update({"testStatus": True})
|
||||
# Delete the document from the source collection
|
||||
db.collection(source_collection).document(doc_id).delete()
|
||||
print(f"Document with ID '{doc_id}' updated")
|
||||
count = count + 1
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user