Skip to content

Commit

Permalink
Updates to fetch script
Browse files Browse the repository at this point in the history
  • Loading branch information
johc committed Mar 27, 2024
1 parent 139b705 commit a243b2f
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
client = MongoClient(os.environ['MONGODB_URI'])
db = client.FMD # Assuming 'FMD' is your database name

# Fetch data from FMD.Endpoints collection
endpoints_data = list(db.Endpoints.find({}))
# Function to fetch and save collection data
def fetch_and_save(collection_name, file_path):
data = list(db[collection_name].find({}))
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with open(file_path, '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 and save FMD.Endpoints
fetch_and_save("Endpoints", 'fmd-telemetry/fmd-telemetry/src/assets/Endpoints.json')

# 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)
# Fetch and save FMD.UserSession
fetch_and_save("UserSession", 'fmd-telemetry/fmd-telemetry/src/assets/UserSession.json')

0 comments on commit a243b2f

Please sign in to comment.