From 85c7cdec0635ec0b6257117d7cdf162f70e714e4 Mon Sep 17 00:00:00 2001 From: johc Date: Wed, 27 Mar 2024 13:34:55 +0100 Subject: [PATCH] Updates to fetch script --- fetch_data.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/fetch_data.py b/fetch_data.py index aa0e92e..17cd94d 100644 --- a/fetch_data.py +++ b/fetch_data.py @@ -4,12 +4,22 @@ # Connect to MongoDB client = MongoClient(os.environ['MONGODB_URI']) -db = client.your_database_name # Replace with your database name +db = client.FMD # Assuming 'FMD' is your database name -# Fetch data from a collection -collection = db.your_collection_name # Replace with your collection name -data = list(collection.find({})) +# Fetch data from FMD.Endpoints collection +endpoints_data = list(db.Endpoints.find({})) -# Save to a JSON file -with open('data.json', 'w') as file: - json.dump(data, file) +# Save Endpoints data to a JSON file +endpoints_file_path = 'fmd-telemetry/fmd-telemetry/src/assets/Endpoints.json' +os.makedirs(os.path.dirname(endpoints_file_path), exist_ok=True) +with open(endpoints_file_path, 'w') as file: + json.dump(endpoints_data, file) + +# Fetch data from FMD.UserSession collection +user_session_data = list(db.UserSession.find({})) + +# Save UserSession data to a JSON file +user_session_file_path = 'fmd-telemetry/fmd-telemetry/src/assets/UserSession.json' +os.makedirs(os.path.dirname(user_session_file_path), exist_ok=True) +with open(user_session_file_path, 'w') as file: + json.dump(user_session_data, file)