awacke1 commited on
Commit
8b66346
·
1 Parent(s): f05b0a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -2,6 +2,8 @@ import os
2
  import streamlit as st
3
  from azure.cosmos import CosmosClient, PartitionKey
4
  from azure.storage.blob import BlobServiceClient
 
 
5
  import requests
6
  import glob
7
 
@@ -39,15 +41,14 @@ def display_cosmos_db_structure():
39
  st.markdown(item_desc)
40
 
41
 
42
-
43
  # Function to Add or Update an Item
44
- def add_or_update_item(database_client, container_name, item_id, item_data):
45
- container = database_client.get_container_client(container_name)
46
  try:
47
  existing_item = container.read_item(item_id, partition_key=PartitionKey(item_id))
48
  existing_item.update(item_data)
49
  container.replace_item(item_id, existing_item)
50
- except:
51
  container.create_item(item_data)
52
 
53
  # Function to Add or Update an Item
 
2
  import streamlit as st
3
  from azure.cosmos import CosmosClient, PartitionKey
4
  from azure.storage.blob import BlobServiceClient
5
+ from azure.cosmos.exceptions import CosmosResourceNotFoundError
6
+
7
  import requests
8
  import glob
9
 
 
41
  st.markdown(item_desc)
42
 
43
 
 
44
  # Function to Add or Update an Item
45
+ def add_or_update_item(database_name, container_name, item_id, item_data):
46
+ container = cosmos_client.get_database_client(database_name).get_container_client(container_name)
47
  try:
48
  existing_item = container.read_item(item_id, partition_key=PartitionKey(item_id))
49
  existing_item.update(item_data)
50
  container.replace_item(item_id, existing_item)
51
+ except CosmosResourceNotFoundError:
52
  container.create_item(item_data)
53
 
54
  # Function to Add or Update an Item