add date range for buffers
This commit is contained in:
@@ -7,32 +7,29 @@ import pandas as pd
|
||||
from datetime import datetime
|
||||
import sys
|
||||
|
||||
# Initialize Firebase Admin SDK
|
||||
cred = credentials.Certificate(os.getcwd() + '/' + 'keys/hpos-prod-firebase-adminsdk.json') # Replace with your own service account key path
|
||||
firebase_admin.initialize_app(cred)
|
||||
|
||||
# Get a reference to the Firestore database
|
||||
db = firestore.client()
|
||||
|
||||
# Specify the collections
|
||||
buffers_collection = db.collection("buffers")
|
||||
start_date = sys.argv[1]
|
||||
end_date = sys.argv[2]
|
||||
|
||||
buffers_collection = db.collection("buffers").where(filter=FieldFilter("testTime", ">=", start_date)).where(filter=FieldFilter("testTime", "<", end_date))
|
||||
docs = buffers_collection.stream()
|
||||
|
||||
# Prepare data to store in CSV
|
||||
data = []
|
||||
for doc in docs:
|
||||
doc_data = doc.to_dict()
|
||||
|
||||
data.append(doc_data)
|
||||
|
||||
# Convert the data to a DataFrame
|
||||
df = pd.DataFrame(data)
|
||||
print(df)
|
||||
print(df.size)
|
||||
|
||||
# print("duplicates", len(df['_id']) - len(df['_id'].drop_duplicates()))
|
||||
|
||||
# Save the DataFrame to a CSV file
|
||||
output_filename = f'buffers_{datetime.today().strftime("%d_%m_%Y_%H_%M")}.xlsx'
|
||||
|
||||
downloads_dir = os.path.join(os.path.expanduser("~"), "Downloads")
|
||||
@@ -44,6 +41,5 @@ writer.close()
|
||||
|
||||
print(f"Data saved to '{output_path}'")
|
||||
|
||||
# Close the Firebase Admin SDK
|
||||
firebase_admin.delete_app(firebase_admin.get_app())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user