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