James McCool
commited on
Commit
·
c1c18f8
1
Parent(s):
00d6b89
Enhance contest data retrieval by adding secondary date parameter
Browse files- Updated the grab_contest_data function to accept a second date parameter, allowing for fallback retrieval of contest data if the primary date fails.
- Modified app.py to calculate and pass the next day's date to the data retrieval function, improving data loading reliability.
- Maintained existing functionality while enhancing the robustness of the contest data loading process.
- app.py +2 -1
- global_func/grab_contest_data.py +5 -3
app.py
CHANGED
@@ -64,6 +64,7 @@ with tab1:
|
|
64 |
date_list = curr_info['Date'].sort_values(ascending=False).unique()
|
65 |
date_list = date_list[date_list != pd.Timestamp.today().strftime('%Y-%m-%d')]
|
66 |
date_select = st.selectbox("Select Date", date_list, key='date_select')
|
|
|
67 |
|
68 |
name_parse = curr_info[curr_info['Date'] == date_select]['Contest Name'].reset_index(drop=True)
|
69 |
date_select = date_select.replace('-', '')
|
@@ -78,7 +79,7 @@ with tab1:
|
|
78 |
del st.session_state['Contest_file']
|
79 |
if 'Contest_file' not in st.session_state:
|
80 |
if st.button('Load Contest Data', key='load_contest_data'):
|
81 |
-
st.session_state['Contest_file'] = grab_contest_data(sport_select, contest_name_var, contest_id_map, date_select)
|
82 |
else:
|
83 |
pass
|
84 |
with col2:
|
|
|
64 |
date_list = curr_info['Date'].sort_values(ascending=False).unique()
|
65 |
date_list = date_list[date_list != pd.Timestamp.today().strftime('%Y-%m-%d')]
|
66 |
date_select = st.selectbox("Select Date", date_list, key='date_select')
|
67 |
+
date_select2 = (pd.to_datetime(date_select) + pd.Timedelta(days=1)).strftime('%Y-%m-%d')
|
68 |
|
69 |
name_parse = curr_info[curr_info['Date'] == date_select]['Contest Name'].reset_index(drop=True)
|
70 |
date_select = date_select.replace('-', '')
|
|
|
79 |
del st.session_state['Contest_file']
|
80 |
if 'Contest_file' not in st.session_state:
|
81 |
if st.button('Load Contest Data', key='load_contest_data'):
|
82 |
+
st.session_state['Contest_file'] = grab_contest_data(sport_select, contest_name_var, contest_id_map, date_select, date_select2)
|
83 |
else:
|
84 |
pass
|
85 |
with col2:
|
global_func/grab_contest_data.py
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
import pandas as pd
|
2 |
import requests
|
3 |
|
4 |
-
def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
|
5 |
|
6 |
contest_id = contest_id_map[contest_name]
|
7 |
-
|
8 |
-
|
|
|
|
|
9 |
data_url = raw_url + 'data/'
|
10 |
lineups_url = raw_url + 'lineups/'
|
11 |
|
|
|
1 |
import pandas as pd
|
2 |
import requests
|
3 |
|
4 |
+
def grab_contest_data(sport, contest_name, contest_id_map, contest_date, contest_date2):
|
5 |
|
6 |
contest_id = contest_id_map[contest_name]
|
7 |
+
try:
|
8 |
+
raw_url = f'https://dh5nxc6yx3kwy.cloudfront.net/contests/{sport.lower()}/{contest_date}/{contest_id}/'
|
9 |
+
except:
|
10 |
+
raw_url = f'https://dh5nxc6yx3kwy.cloudfront.net/contests/{sport.lower()}/{contest_date2}/{contest_id}/'
|
11 |
data_url = raw_url + 'data/'
|
12 |
lineups_url = raw_url + 'lineups/'
|
13 |
|