James McCool commited on
Commit
de7aa9f
·
1 Parent(s): 39841d9

Refactor contest data import logic in app.py

Browse files

- Simplified the error handling during contest data import by initializing an empty DataFrame with specified columns in case of failure.
- Moved the check for existing contest data to a more streamlined position, enhancing code readability and maintaining user feedback for duplicate uploads.

Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -63,12 +63,11 @@ def export_contest_file(db, sport, type, contest_date, contest_id, contest_data)
63
  try:
64
  cursor = collection.find()
65
  contest_import = pd.DataFrame(list(cursor)).drop('_id', axis=1)
 
 
 
66
  except:
67
- contest_import = pd.DataFrame(columns = contest_data.columns)
68
-
69
- if contest_id in contest_import['Contest ID'].values:
70
- st.info("Data for this contest already exists, no need to upload, but we appreciate the effort!")
71
- return
72
 
73
  contest_data['Contest Date'] = contest_date
74
  contest_data['Contest ID'] = contest_id
 
63
  try:
64
  cursor = collection.find()
65
  contest_import = pd.DataFrame(list(cursor)).drop('_id', axis=1)
66
+ if contest_id in contest_import['Contest ID'].values:
67
+ st.info("Data for this contest already exists, no need to upload, but we appreciate the effort!")
68
+ return
69
  except:
70
+ contest_import = pd.DataFrame(columns = ['Rank', 'EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS', 'Contest Date', 'Contest ID'])
 
 
 
 
71
 
72
  contest_data['Contest Date'] = contest_date
73
  contest_data['Contest ID'] = contest_id