47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
import os
|
|
import firebase_admin
|
|
from firebase_admin import credentials
|
|
from firebase_admin import firestore
|
|
from google.cloud.firestore_v1.base_query import FieldFilter
|
|
import pandas as pd
|
|
#import datetime
|
|
import sys
|
|
from datetime import datetime
|
|
import matplotlib.pyplot as plt
|
|
|
|
cred = credentials.Certificate(os.getcwd() + '/keys/hpos-prod-firebase-adminsdk.json') # Replace with your own service account key path
|
|
firebase_admin.initialize_app(cred)
|
|
|
|
db = firestore.client()
|
|
|
|
patient_collection = db.collection("patientData")
|
|
# test_collection = db.collection("testData")
|
|
start_date = sys.argv[1]
|
|
end_date = sys.argv[2]
|
|
|
|
query = patient_collection.where(filter=FieldFilter("createdAt", ">=", start_date)).where(filter=FieldFilter("createdAt", "<", end_date))
|
|
patient_docs = query.stream()
|
|
|
|
data = []
|
|
for patient_doc in patient_docs:
|
|
patient_data = patient_doc.to_dict()
|
|
data.append(patient_data)
|
|
|
|
df = pd.DataFrame(data)
|
|
print(df)
|
|
print(df.size)
|
|
|
|
print("duplicates", len(df['_id']) - len(df['_id'].drop_duplicates()))
|
|
|
|
output_filename = f'users_{datetime.today().strftime("%d_%m_%Y_%H_%M")}.xlsx'
|
|
df.to_excel(output_filename, index=False)
|
|
|
|
downloads_dir = os.path.join(os.path.expanduser("~"), "Downloads")
|
|
output_path = os.path.join(downloads_dir, output_filename)
|
|
df.to_excel(output_path, index=False)
|
|
|
|
print(f"Data saved to '{output_path}'")
|
|
|
|
firebase_admin.delete_app(firebase_admin.get_app())
|
|
|