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 google.cloud.firestore_v1.base_query import FieldFilter
|
||||||
from firebase_admin import initialize_app, credentials, firestore
|
from firebase_admin import initialize_app, credentials, firestore
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
initialize_app()
|
initialize_app()
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ def clear_users(request):
|
|||||||
source_collection = "patientData"
|
source_collection = "patientData"
|
||||||
|
|
||||||
# Get all documents from the source collection
|
# 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
|
count = 0
|
||||||
for doc in source_docs:
|
for doc in source_docs:
|
||||||
# Extract the document ID
|
# Extract the document ID
|
||||||
@@ -45,7 +46,8 @@ def clear_users(request):
|
|||||||
doc_data = doc.to_dict()
|
doc_data = doc.to_dict()
|
||||||
|
|
||||||
try:
|
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")
|
print(f"Document with ID '{doc_id}' updated")
|
||||||
count = count + 1
|
count = count + 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user