Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
bd47315
1
Parent(s):
61123ac
Refactor MongoDB connection in Streamlit app to use environment variable for URI instead of secrets, improving flexibility for deployment.
Browse files- src/streamlit_app.py +7 -6
src/streamlit_app.py
CHANGED
|
@@ -3,18 +3,19 @@ import pandas as pd
|
|
| 3 |
import streamlit as st
|
| 4 |
from itertools import combinations
|
| 5 |
import pymongo
|
|
|
|
| 6 |
|
| 7 |
st.set_page_config(layout="wide")
|
| 8 |
|
| 9 |
@st.cache_resource
|
| 10 |
def init_conn():
|
| 11 |
-
|
| 12 |
-
uri = st.secrets['mongo_uri']
|
| 13 |
-
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
| 14 |
-
db = client["MLB_Database"]
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
db = init_conn()
|
| 19 |
|
| 20 |
game_format = {'Win Percentage': '{:.2%}','First Inning Lead Percentage': '{:.2%}',
|
|
|
|
| 3 |
import streamlit as st
|
| 4 |
from itertools import combinations
|
| 5 |
import pymongo
|
| 6 |
+
import os
|
| 7 |
|
| 8 |
st.set_page_config(layout="wide")
|
| 9 |
|
| 10 |
@st.cache_resource
|
| 11 |
def init_conn():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
uri = os.getenv('mongo_uri')
|
| 14 |
+
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
| 15 |
+
db = client["MLB_Database"]
|
| 16 |
+
|
| 17 |
+
return db
|
| 18 |
+
|
| 19 |
db = init_conn()
|
| 20 |
|
| 21 |
game_format = {'Win Percentage': '{:.2%}','First Inning Lead Percentage': '{:.2%}',
|