From 7275c42af53aa0387fc48875316acc214d43b693 Mon Sep 17 00:00:00 2001 From: Eduardo Figueroa Date: Tue, 9 Sep 2025 15:58:07 -0700 Subject: [PATCH] Fixed week displaying to week 1 instead of current week. typeerror issue on matchup --- .gitignore | 201 +++++++++++++++++++++++++++++++++++++++++++ app.py | 20 +++-- services/espn_api.py | 9 +- 3 files changed, 220 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d3168d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,201 @@ +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +Pipfile.lock + +# poetry +poetry.lock + +# pdm +.pdm.toml + +# PEP 582 +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +.idea/ + +# Vim +*~ +*.swp +*.swo +.*.swp +.*.swo +*.tmp +*.orig +Session.vim +.netrwhist +tags + +# Emacs +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Archives +*.tar +*.tar.gz +*.tar.bz2 +*.tar.xz +*.tgz +*.tbz2 +*.txz +*.zip +*.rar +*.7z +*.gz +*.bz2 +*.xz +*.Z +*.lz +*.lzma +*.cab +*.deb +*.rpm +*.dmg +*.iso + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# IDE +.vscode/ +*.sublime-project +*.sublime-workspace + +# Local development +.env.local +.env.development +.env.test +.env.production +config.local.py \ No newline at end of file diff --git a/app.py b/app.py index 8f24678..9069e13 100644 --- a/app.py +++ b/app.py @@ -108,7 +108,7 @@ def dashboard_current(username): print(f"DEBUG: Dashboard current route - username: '{username}'", flush=True) try: nfl_state = sleeper_api.get_nfl_state() - current_week = nfl_state.get('display_week', 1) + current_week = nfl_state.get('week', 1) print(f"DEBUG: Current week: {current_week}", flush=True) return dashboard(username, current_week) except Exception as e: @@ -194,15 +194,17 @@ def dashboard(username, week): user_roster = next((r for r in rosters if r['owner_id'] == user['user_id']), None) print(f"DEBUG: User roster found: {user_roster is not None}", flush=True) - if user_roster and matchups: - # Find user's matchup for this week - user_matchup = next((m for m in matchups if m['roster_id'] == user_roster['roster_id']), None) + if user_roster: + # Find user's matchup for this week (if matchups exist) + user_matchup = None + if matchups: + user_matchup = next((m for m in matchups if m['roster_id'] == user_roster['roster_id']), None) print(f"DEBUG: User matchup found: {user_matchup is not None}", flush=True) # Find opponent's matchup and user info opponent_matchup = None opponent_user = None - if user_matchup: + if user_matchup and matchups: # Find opponent in same matchup opponent_matchup = next((m for m in matchups if m['matchup_id'] == user_matchup['matchup_id'] and m['roster_id'] != user_roster['roster_id']), None) print(f"DEBUG: Opponent matchup found: {opponent_matchup is not None}", flush=True) @@ -218,10 +220,12 @@ def dashboard(username, week): # Get all players on user's roster for calendar with starter info all_players = [] - if user_roster and user_roster.get('players') and user_matchup: + if user_roster and user_roster.get('players'): players_list = user_roster['players'] - starters_list = user_matchup.get('starters', []) - players_points = user_matchup.get('players_points', {}) + starters_list = user_matchup.get('starters') if user_matchup else None + starters_list = starters_list or [] # Handle None case + players_points = user_matchup.get('players_points') if user_matchup else None + players_points = players_points or {} # Handle None case print(f"DEBUG: Processing {len(players_list)} total players, {len(starters_list)} starters", flush=True) for player_id in players_list: diff --git a/services/espn_api.py b/services/espn_api.py index 8c92e9d..4ce9f62 100644 --- a/services/espn_api.py +++ b/services/espn_api.py @@ -40,9 +40,14 @@ class ESPNAPI: try: print(f"ESPN API: Fetching schedule for week {week}, season {season}", flush=True) - # Get current NFL scoreboard + # Get NFL scoreboard for specific week and season url = f"{self.BASE_URL}/scoreboard" - response = self.session.get(url) + params = { + 'seasontype': 2, # Regular season + 'week': week, + 'year': season + } + response = self.session.get(url, params=params) response.raise_for_status() data = response.json()