-
Notifications
You must be signed in to change notification settings - Fork 0
misc unmerged from lineup data #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
52149a1
misc leftover
RickArko 2f2e60e
Fix flaky CFB roster availability tests against live sportsdataverse …
RickArko 927edbf
resolve merge
RickArko beee9d0
Address Copilot review on ingest CLI and ESPN auth handling.
RickArko 5f50871
Ignore local pre-commit home directory used for sandbox-safe hooks.
RickArko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,4 +31,6 @@ data/exports/ | |
| .coverage.* | ||
| htmlcov/ | ||
| .pytest_cache/ | ||
| .pre-commit-cache/ | ||
| .pre-commit-home/ | ||
| .ai/* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| """FFPy league data ingestion CLI. | ||
|
|
||
| Usage: | ||
| ffpy-ingest espn <league_id> [--season N] [--json|--csv] [--db PATH] [--swid ...] [--s2 ...] | ||
| ffpy-ingest yahoo <league_id> [--season N] [--json|--csv] [--db PATH] [--token ...] | ||
| ffpy-ingest sleeper <league_id> [--season N] [--json|--csv] [--db PATH] | ||
| ffpy-ingest yahoo-auth | ||
| ffpy-ingest yahoo-token --code CODE | ||
| ffpy-ingest leagues-list [--json|--csv] [--db PATH] | ||
| ffpy-ingest leagues-info <id> [--json|--csv] [--db PATH] | ||
| ffpy-ingest roster <league_id> <team_id> [--json|--csv] [--db PATH] | ||
| ffpy-ingest matchups <league_id> <week> [--json|--csv] [--db PATH] | ||
| """ | ||
|
|
||
| from . import auth, cli, espn, output, sleeper, yahoo | ||
|
|
||
| __all__ = ["auth", "cli", "espn", "output", "sleeper", "yahoo"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| """Auth helpers for ingest CLI: cookie files, token file I/O, env helpers.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import logging | ||
| import os | ||
| import time | ||
| from pathlib import Path | ||
| from typing import Optional | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| TOKEN_DIR = Path.home() / ".ffpy" | ||
| TOKEN_FILE = TOKEN_DIR / "yahoo_token.json" | ||
| COOKIE_FILE = TOKEN_DIR / "espn_cookies.json" | ||
|
|
||
|
|
||
| def _ensure_dir() -> None: | ||
| TOKEN_DIR.mkdir(parents=True, exist_ok=True) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Yahoo token file | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def load_yahoo_token() -> Optional[dict]: | ||
| """Load Yahoo OAuth token from ~/.ffpy/yahoo_token.json if valid.""" | ||
| if not TOKEN_FILE.exists(): | ||
| return None | ||
| try: | ||
| data = json.loads(TOKEN_FILE.read_text()) | ||
| except (json.JSONDecodeError, OSError): | ||
| logger.warning("Corrupt Yahoo token file: %s", TOKEN_FILE) | ||
| return None | ||
|
|
||
| expires_at = data.get("expires_at", 0) | ||
| if time.time() >= expires_at: | ||
| logger.info("Yahoo token expired — caller should refresh") | ||
| return data | ||
|
|
||
|
|
||
| def save_yahoo_token(token: dict) -> None: | ||
| """Persist Yahoo OAuth token to ~/.ffpy/yahoo_token.json.""" | ||
| _ensure_dir() | ||
| TOKEN_FILE.write_text(json.dumps(token, indent=2)) | ||
| TOKEN_FILE.chmod(0o600) | ||
| logger.info("Yahoo token saved to %s", TOKEN_FILE) | ||
|
|
||
|
|
||
| def delete_yahoo_token() -> None: | ||
| """Remove stored Yahoo token.""" | ||
| if TOKEN_FILE.exists(): | ||
| TOKEN_FILE.unlink() | ||
| logger.info("Yahoo token deleted") | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # ESPN cookie file | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def load_espn_cookies() -> tuple[str, str]: | ||
| """Load ESPN cookies from ~/.ffpy/espn_cookies.json or env vars.""" | ||
| swid = os.getenv("ESPN_SWID", "") | ||
| s2 = os.getenv("ESPN_S2", "") | ||
|
|
||
| if not swid or not s2: | ||
| if COOKIE_FILE.exists(): | ||
| try: | ||
| data = json.loads(COOKIE_FILE.read_text()) | ||
| swid = data.get("swid", swid) | ||
| s2 = data.get("espn_s2", s2) | ||
| except (json.JSONDecodeError, OSError): | ||
| pass | ||
|
|
||
| return swid, s2 | ||
|
|
||
|
|
||
| def save_espn_cookies(swid: str, espn_s2: str) -> None: | ||
| """Persist ESPN cookies to ~/.ffpy/espn_cookies.json.""" | ||
| _ensure_dir() | ||
| COOKIE_FILE.write_text(json.dumps({"swid": swid, "espn_s2": espn_s2}, indent=2)) | ||
| COOKIE_FILE.chmod(0o600) | ||
| logger.info("ESPN cookies saved to %s", COOKIE_FILE) | ||
|
Copilot marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def delete_espn_cookies() -> None: | ||
| if COOKIE_FILE.exists(): | ||
| COOKIE_FILE.unlink() | ||
| logger.info("ESPN cookies deleted") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.