Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,44 +14,25 @@ cosmos_client = CosmosClient.from_connection_string(COSMOS_CONNECTION_STRING)
|
|
14 |
# Initialize Azure Blob Storage Client
|
15 |
blob_service = BlobServiceClient.from_connection_string(BLOB_STORAGE_CONNECTION_STRING)
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
for container_name, items in containers_info:
|
37 |
-
st.subheader(f'Container: {container_name}')
|
38 |
-
for item in items:
|
39 |
-
st.json(item)
|
40 |
-
|
41 |
-
selected_db_for_listing = st.text_input('Enter Database Name to List Containers and Items')
|
42 |
-
emoji_button = st.button('🔍 Retrieve Data')
|
43 |
-
|
44 |
-
if emoji_button:
|
45 |
-
if selected_db_for_listing:
|
46 |
-
containers_info = get_containers_and_items(selected_db_for_listing)
|
47 |
-
for container_name, items in containers_info:
|
48 |
-
st.subheader(f'Container: {container_name}')
|
49 |
-
for item in items:
|
50 |
-
st.json(item)
|
51 |
-
else:
|
52 |
-
st.error('Please enter a database name.')
|
53 |
-
|
54 |
-
|
55 |
|
56 |
# Streamlit UI
|
57 |
st.title('Azure Services Integration with Streamlit')
|
|
|
14 |
# Initialize Azure Blob Storage Client
|
15 |
blob_service = BlobServiceClient.from_connection_string(BLOB_STORAGE_CONNECTION_STRING)
|
16 |
|
17 |
+
# Function to Get Databases, Containers, and Items
|
18 |
+
def get_databases_containers_and_items():
|
19 |
+
all_data = []
|
20 |
+
for db_properties in cosmos_client.list_databases():
|
21 |
+
db_name = db_properties['id']
|
22 |
+
database_client = cosmos_client.get_database_client(db_name)
|
23 |
+
for container_properties in database_client.list_containers():
|
24 |
+
container_name = container_properties['id']
|
25 |
+
container_client = database_client.get_container_client(container_name)
|
26 |
+
items = list(container_client.read_all_items())
|
27 |
+
all_data.append({'database': db_name, 'container': container_name, 'items': items})
|
28 |
+
return all_data
|
29 |
+
|
30 |
+
# Displaying the Data
|
31 |
+
all_data = get_databases_containers_and_items()
|
32 |
+
for data in all_data:
|
33 |
+
st.subheader(f"Database: {data['database']}, Container: {data['container']}")
|
34 |
+
for item in data['items']:
|
35 |
+
st.json(item)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# Streamlit UI
|
38 |
st.title('Azure Services Integration with Streamlit')
|