buffers for kit prechecks
This commit is contained in:
49
scripts/buffers.py
Normal file
49
scripts/buffers.py
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
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
|
||||||
|
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")
|
||||||
|
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")
|
||||||
|
output_path = os.path.join(downloads_dir, output_filename)
|
||||||
|
writer = pd.ExcelWriter(output_path, engine = 'openpyxl')
|
||||||
|
df.to_excel(writer, sheet_name = 'data', index=False)
|
||||||
|
# df_count.to_excel(writer, sheet_name = "count")
|
||||||
|
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