James McCool
Refactor file type checks in load_file.py and load_ss_file.py: streamline file extension validation using endswith method for improved readability. Update app.py to handle salary conversion more robustly by removing unnecessary exception handling.
9d66c9c
| import streamlit as st | |
| import numpy as np | |
| import pandas as pd | |
| import time | |
| from fuzzywuzzy import process | |
| import re | |
| def load_dk_fd_file(lineups, csv_file): | |
| df = csv_file.copy() | |
| try: | |
| name_dict = dict(zip(df['Name + ID'], df['Name'])) | |
| except: | |
| name_dict = dict(zip(df['Id'], df['Nickname'])) | |
| # Now load and process the lineups file | |
| try: | |
| clean_name = re.sub(r' \(\d+\)', '', lineups.name) | |
| print(clean_name) | |
| print(lineups.name) | |
| if clean_name.endswith('.csv'): | |
| lineups_df = pd.read_csv(lineups) | |
| elif clean_name.endswith(('.xls', '.xlsx')): | |
| lineups_df = pd.read_excel(lineups) | |
| else: | |
| st.error('Please upload either a CSV or Excel file for lineups') | |
| return None, None | |
| print(lineups_df) | |
| try: | |
| lineups_df = lineups_df.drop(columns=['Entry ID', 'Contest Name', 'Contest ID', 'Entry Fee']) | |
| except: | |
| pass | |
| export_df = lineups_df.copy() | |
| # Map the IDs to names | |
| for col in lineups_df.columns: | |
| lineups_df[col] = lineups_df[col].map(name_dict) | |
| return export_df, lineups_df | |
| except Exception as e: | |
| st.error(f'Error loading lineups file: {str(e)}') | |
| return None, None |