Fixed week displaying to week 1 instead of current week. typeerror issue

on matchup
This commit is contained in:
Eduardo Figueroa 2025-09-09 15:58:07 -07:00
parent 329f2bfea6
commit 7275c42af5
3 changed files with 220 additions and 10 deletions

201
.gitignore vendored Normal file
View file

@ -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

18
app.py
View file

@ -108,7 +108,7 @@ def dashboard_current(username):
print(f"DEBUG: Dashboard current route - username: '{username}'", flush=True) print(f"DEBUG: Dashboard current route - username: '{username}'", flush=True)
try: try:
nfl_state = sleeper_api.get_nfl_state() 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) print(f"DEBUG: Current week: {current_week}", flush=True)
return dashboard(username, current_week) return dashboard(username, current_week)
except Exception as e: 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) 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) print(f"DEBUG: User roster found: {user_roster is not None}", flush=True)
if user_roster and matchups: if user_roster:
# Find user's matchup for this week # 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) 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) print(f"DEBUG: User matchup found: {user_matchup is not None}", flush=True)
# Find opponent's matchup and user info # Find opponent's matchup and user info
opponent_matchup = None opponent_matchup = None
opponent_user = None opponent_user = None
if user_matchup: if user_matchup and matchups:
# Find opponent in same matchup # 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) 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) 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 # Get all players on user's roster for calendar with starter info
all_players = [] 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'] players_list = user_roster['players']
starters_list = user_matchup.get('starters', []) starters_list = user_matchup.get('starters') if user_matchup else None
players_points = user_matchup.get('players_points', {}) 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) print(f"DEBUG: Processing {len(players_list)} total players, {len(starters_list)} starters", flush=True)
for player_id in players_list: for player_id in players_list:

View file

@ -40,9 +40,14 @@ class ESPNAPI:
try: try:
print(f"ESPN API: Fetching schedule for week {week}, season {season}", flush=True) 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" 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() response.raise_for_status()
data = response.json() data = response.json()