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